Nushell
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
GitHub
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
GitHub
  • Categories

    • Bits
    • Bytes
    • Chart
    • Conversions
    • Core
    • Database
    • Dataframe
    • Dataframe Or Lazyframe
    • Date
    • Debug
    • Default
    • Env
    • Experimental
    • Expression
    • Filesystem
    • Filters
    • Formats
    • Generators
    • Hash
    • History
    • Lazyframe
    • Math
    • Misc
    • Network
    • Path
    • Platform
    • Plugin
    • Prompt
    • Random
    • Removed
    • Shells
    • Strings
    • System
    • Viewers

to xml for formats

Convert special record structure into .xml text.

Signature

> to xml {flags}

Flags

  • --indent, -i {int}: Formats the XML text with the provided indentation setting
  • --partial-escape, -p: Only escape mandatory characters in text and attributes
  • --self-closed, -s: Output empty tags as self closing

Input/output types:

inputoutput
recordstring

Examples

Outputs an XML string representing the contents of this table

> {tag: note attributes: {} content : [{tag: remember attributes: {} content : [{tag: null attributes: null content : Event}]}]} | to xml
<note><remember>Event</remember></note>

When formatting xml null and empty record fields can be omitted and strings can be written without a wrapping record

> {tag: note content : [{tag: remember content : [Event]}]} | to xml
<note><remember>Event</remember></note>

Optionally, formats the text with a custom indentation setting

> {tag: note content : [{tag: remember content : [Event]}]} | to xml --indent 3
<note>
   <remember>Event</remember>
</note>

Produce less escaping sequences in resulting xml

> {tag: note attributes: {a: "'qwe'\\"} content: ["\"'"]} | to xml --partial-escape
<note a="'qwe'\">"'</note>

Save space using self-closed tags

> {tag: root content: [[tag]; [a] [b] [c]]} | to xml --self-closed
<root><a/><b/><c/></root>

Notes

Every XML entry is represented via a record with tag, attribute and content fields. To represent different types of entries different values must be written to this fields:

  1. Tag entry: {tag: <tag name> attributes: {<attr name>: "<string value>" ...} content: [<entries>]}
  2. Comment entry: {tag: '!' attributes: null content: "<comment string>"}
  3. Processing instruction (PI): {tag: '?<pi name>' attributes: null content: "<pi content string>"}
  4. Text: {tag: null attributes: null content: "<text>"}. Or as plain <text> instead of record.

Additionally any field which is: empty record, empty list or null, can be omitted.