diff --git a/pkg/yqlib/decode_xml_test.go b/pkg/yqlib/decode_xml_test.go index 714e4c7c..cf1e2427 100644 --- a/pkg/yqlib/decode_xml_test.go +++ b/pkg/yqlib/decode_xml_test.go @@ -41,13 +41,13 @@ var xmlScenarios = []xmlScenario{ { description: "Parse xml: array", subdescription: "Consecutive nodes with identical xml names are assumed to be arrays.", - inputXml: "\n12", + inputXml: "\n1\n2", expected: "D0, P[], (doc)::animal:\n - \"1\"\n - \"2\"\n", }, { description: "Parse xml: attributes", subdescription: "Attributes are converted to fields, with the attribute prefix.", - inputXml: "\n7", + inputXml: "\n\n 7\n", expected: "D0, P[], (doc)::cat:\n +legs: \"4\"\n legs: \"7\"\n", }, { diff --git a/pkg/yqlib/doc/usage/xml.md b/pkg/yqlib/doc/usage/xml.md index 245f9cbd..e084149e 100644 --- a/pkg/yqlib/doc/usage/xml.md +++ b/pkg/yqlib/doc/usage/xml.md @@ -4,7 +4,12 @@ At the moment, `yq` only supports decoding `xml` (into one of the other supporte As yaml does not have the concept of attributes, these are converted to regular fields with a prefix to prevent clobbering. Consecutive xml nodes with the same name are assumed to be arrays. -All values in XML are assumed to be strings. +All values in XML are assumed to be strings - but you can use `from_yaml` to parse them into their correct types: + + +``` +yq e -p=xml '.myNumberField |= from_yaml' my.xml +``` ## Parse xml: simple Given a sample.xml file of: @@ -27,7 +32,8 @@ Consecutive nodes with identical xml names are assumed to be arrays. Given a sample.xml file of: ```xml -12 +1 +2 ``` then ```bash @@ -46,7 +52,9 @@ Attributes are converted to fields, with the attribute prefix. Given a sample.xml file of: ```xml -7 + + 7 + ``` then ```bash