diff --git a/pkg/yqlib/encoder_xml.go b/pkg/yqlib/encoder_xml.go index 652d574..0e605c7 100644 --- a/pkg/yqlib/encoder_xml.go +++ b/pkg/yqlib/encoder_xml.go @@ -46,7 +46,7 @@ func (e *xmlEncoder) Encode(writer io.Writer, node *CandidateNode) error { encoder.Indent("", e.indentString) var newLine xml.CharData = []byte("\n") - if node.Tag == "!!map" { + if node.Kind == MappingNode { // make sure processing instructions are encoded first for i := 0; i < len(node.Content); i += 2 { key := node.Content[i] diff --git a/pkg/yqlib/xml_test.go b/pkg/yqlib/xml_test.go index 7628ae1..9320f6d 100644 --- a/pkg/yqlib/xml_test.go +++ b/pkg/yqlib/xml_test.go @@ -557,6 +557,20 @@ var xmlScenarios = []formatScenario{ expectedError: "cannot encode !!seq to XML - only maps can be encoded", scenarioType: "encode-error", }, + { + description: "arrays tagged as maps cannot be encoded", + skipDoc: true, + input: "!!map [cat, dog, fish]", + expectedError: "cannot encode !!map to XML - only maps can be encoded", + scenarioType: "encode-error", + }, + { + description: "proc instructions of a map with a custom tag", + skipDoc: true, + input: "!custom\n+p_xml: version=\"1.0\"\na: b\n", + expected: "\nb\n", + scenarioType: "encode", + }, { description: "Encode xml: attributes with content", subdescription: "Fields with the matching xml-content-name is assumed to be content.",