Encode and decode to and from XML. Whitespace is not conserved for round trips - but the order of the fields are.
Consecutive xml nodes with the same name are assumed to be arrays.
XML content data and attributes are created as fields. This can be controlled by the '--xml-attribute-prefix and --xml-content-name flags - see below for examples.
Note that versions prior to 4.18 require the 'eval/e' command to be specified.
yq e <exp> <file>
Parse xml: simple
Notice how all the values are strings, see the next example on how you can fix that.
Given a sample.xml file of:
<?xml version="1.0" encoding="UTF-8"?>
<cat>
<says>meow</says>
<legs>4</legs>
<cute>true</cute>
</cat>
then
yq -p=xml '.' sample.xml
will output
cat:
says: meow
legs:"4"
cute:"true"
Parse xml: number
All values are assumed to be strings when parsing XML, but you can use the from_yaml operator on all the strings values to autoparse into the correct type.