XML guides

Export repeated XML items and quoted identifiers to YAML

·

A YAML mapping has distinct keys, while an XML element can contain several children with the same name. Keeping children in a sequence preserves each occurrence.

XML to YAML Converter

Keep two item elements

Convert <r><item id="007">false</item><item id="009">123</item></r>. In the ordered export both item nodes have a place under children. Their id attributes are strings, and the first text value remains the four letters false.

W3C Extensible Markup Language 1.0YAML 1.2.2 specification

Read a declared boolean

Choose Typed JSON values and use <boolean xmlns="http://www.w3.org/2005/xpath-functions">false</boolean>. This input explicitly requests a boolean value. A YAML parser now reads the scalar as false.

W3C XPath and XQuery Functions and Operators — XML to JSON

Keep a part number distinct from a quantity

In a parts feed, 0012 may be the identifier printed on the box. Saving the digits as a number would discard the zeros. Use the ordered mode on this XML and inspect the attribute and text values in the downloaded YAML.

Part with a leading-zero identifier
<part code="0012"><qty>2</qty></part>
  • Read the YAML back with a YAML parser. The code remains the four-character string 0012 and the XML text 2 is also a string. Apply numeric conversion to the quantity separately if your inventory schema requires it.

Common questions

Where do namespace declarations go?

The ordered mapping includes them in the attributes mapping. A prefixed tag keeps its qualified name.

Can I check the resulting YAML independently?

Download it and open it in the YAML Validator to check that it parses. To inspect data types, use the YAML and JSON Converter on the same file.

Sources

Put it into practice.

Related guides