Home Explore Blog CI



nushell

commands/docs/from_xml.md
97d52d91f837775443b020dc35d51ba0739602168059a67f0000000300000f7e
---
title: from xml
categories: |
  formats
version: 0.104.0
formats: |
  Parse text as .xml and create record.
usage: |
  Parse text as .xml and create record.
editLink: false
contributors: false
---
<!-- This file is automatically generated. Please edit the command in https://github.com/nushell/nushell instead. -->

# `from xml` for [formats](/commands/categories/formats.md)

<div class='command-title'>Parse text as .xml and create record.</div>

## Signature

```> from xml {flags} ```

## Flags

 -  `--keep-comments`: add comment nodes to result
 -  `--allow-dtd`: allow parsing documents with DTDs (may result in exponential entity expansion)
 -  `--keep-pi`: add processing instruction nodes to result


## Input/output types:

| input  | output |
| ------ | ------ |
| string | record |
## Examples

Converts xml formatted string to record
```nu
> '<?xml version="1.0" encoding="UTF-8"?>
<note>
  <remember>Event</remember>
</note>' | from xml
╭────────────┬───────────────────────────────────────────────────────────────────────────╮
│ tag        │ note                                                                      │
│ attributes │ {record 0 fields}                                                         │
│            │ ╭───┬──────────┬───────────────────┬────────────────────────────────────╮ │
│ content    │ │ # │   tag    │    attributes     │              content               │ │
│            │ ├───┼──────────┼───────────────────┼────────────────────────────────────┤ │
│            │ │ 0 │ remember │ {record 0 fields} │ ╭───┬─────┬────────────┬─────────╮ │ │
│            │ │   │          │                   │ │ # │ tag │ attributes │ content │ │ │
│            │ │   │          │                   │ ├───┼─────┼────────────┼─────────┤ │ │
│            │ │   │          │                   │ │ 0 │     │            │ Event   │ │ │
│            │ │   │          │                   │ ╰───┴─────┴────────────┴─────────╯ │ │
│            │ ╰───┴──────────┴───────────────────┴────────────────────────────────────╯ │
╰────────────┴───────────────────────────────────────────────────────────────────────────╯
```

## Notes
Every XML entry is represented via a record with tag, attribute and content fields.
To represent different types of entries different values are written to this fields:
1. Tag entry: `{tag: <tag name> attrs: {<attr name>: "<string value>" ...} content: [<entries>]}`
2. Comment entry: `{tag: '!' attrs: null content: "<comment string>"}`
3. Processing instruction (PI): `{tag: '?<pi name>' attrs: null content: "<pi content string>"}`
4. Text: `{tag: null attrs: null content: "<text>"}`.

Unlike to xml command all null values are always present and text is never represented via plain
string. This way content of every tag is always a table and is easier to parse

Chunks
910adc38 (1st chunk of `commands/docs/from_xml.md`)
Title: from xml
Summary
This command parses text as .xml and creates a record. It has flags for keeping comments, allowing DTDs, and keeping processing instructions. The XML entry is represented via a record with tag, attribute, and content fields. Different types of entries are represented with different values in these fields.