From cd0be2174222c0e5e3ee08fc1ac60db7df346c9a Mon Sep 17 00:00:00 2001 From: leavesster <11785335+leavesster@users.noreply.github.com> Date: Mon, 25 Oct 2021 22:04:02 +0800 Subject: [PATCH] fix: when node is root, not output unnecessary string --- node.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node.go b/node.go index be6e31a..cc8be4b 100644 --- a/node.go +++ b/node.go @@ -142,7 +142,7 @@ func outputXML(buf *bytes.Buffer, n *Node, preserveSpaces bool) { func (n *Node) OutputXML(self bool) string { preserveSpaces := calculatePreserveSpaces(n, false) var buf bytes.Buffer - if self { + if self && n.Type != DocumentNode { outputXML(&buf, n, preserveSpaces) } else { for n := n.FirstChild; n != nil; n = n.NextSibling {