Skip to content

Conversation

@james-lawrence
Copy link
Contributor

better configurable formatting of XML output. just opening in case its wanted. didn't integrate it with prexisting methods.

@coveralls
Copy link

Coverage Status

Coverage decreased (-3.3%) to 89.271% when pulling 8cd5975 on james-lawrence:enh/formatter into e73954f on antchfx:master.

@zhengchun
Copy link
Contributor

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()
}

@james-lawrence
Copy link
Contributor Author

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)

@james-lawrence james-lawrence deleted the enh/formatter branch October 10, 2023 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants