Closed james-lawrence closed 1 year ago
Good work. I have tested the code. I found DeclarationNode
node will missing its attribute values when called Format()
for example:
xml := `
<?xml version="1.0"?>
<root></root>
`
doc, _:= xmlquery.Parse(strings.NewReader(xml))
fmt.Println(xmlquery.Format(doc))
output:
<?xml?><root></root>
It should output attribute values if they have.
I guess the OutputXML()
method can integrate with your Format()
method, like this:
func (n *Node) OutputXML(self bool) string {
var buf bytes.Buffer
var f formatter
if self {
f.Output(&buf, n)
} else {
for n := n.FirstChild; n != nil; n = n.NextSibling {
f.Output(&buf, n)
}
}
return buf.String()
}
yeah its easy to integrate just didn't want to go the extra step if the code wasn't wanted. I'll clean up this PR soon including fixing the declaration. (didn't care for my usecase because the declaration isn't really useful)
better configurable formatting of XML output. just opening in case its wanted. didn't integrate it with prexisting methods.