Skip to content

Commit

Permalink
Merge branch '#72' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengchun committed Oct 25, 2021
2 parents 0960309 + eca2fa0 commit 95ebf6b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 7 additions & 7 deletions parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ func TestStreamParser_Success1(t *testing.T) {
}
testOutputXML(t, "first call result", `<BBB>b1</BBB>`, n)
testOutputXML(t, "doc after first call",
`<><?xml?><ROOT><AAA><CCC>c1</CCC><BBB>b1</BBB></AAA></ROOT></>`, findRoot(n))
`<?xml?><ROOT><AAA><CCC>c1</CCC><BBB>b1</BBB></AAA></ROOT>`, findRoot(n))

// Second `<BBB>` read
n, err = sp.Read()
Expand All @@ -379,7 +379,7 @@ func TestStreamParser_Success1(t *testing.T) {
}
testOutputXML(t, "second call result", `<BBB>b2<ZZZ z="1">z1</ZZZ></BBB>`, n)
testOutputXML(t, "doc after second call",
`<><?xml?><ROOT><AAA><DDD>d1</DDD><BBB>b2<ZZZ z="1">z1</ZZZ></BBB></AAA></ROOT></>`, findRoot(n))
`<?xml?><ROOT><AAA><DDD>d1</DDD><BBB>b2<ZZZ z="1">z1</ZZZ></BBB></AAA></ROOT>`, findRoot(n))

// Third `<BBB>` read (Note we will skip 'b3' since the streamElementFilter excludes it)
n, err = sp.Read()
Expand All @@ -391,7 +391,7 @@ func TestStreamParser_Success1(t *testing.T) {
// been filtered out and is not our target node, thus it is considered just like any other
// non target nodes such as `<CCC>`` or `<DDD>`
testOutputXML(t, "doc after third call",
`<><?xml?><ROOT><AAA></AAA><ZZZ><BBB>b4</BBB></ZZZ></ROOT></>`,
`<?xml?><ROOT><AAA></AAA><ZZZ><BBB>b4</BBB></ZZZ></ROOT>`,
findRoot(n))

// Fourth `<BBB>` read
Expand All @@ -401,7 +401,7 @@ func TestStreamParser_Success1(t *testing.T) {
}
testOutputXML(t, "fourth call result", `<BBB>b5</BBB>`, n)
testOutputXML(t, "doc after fourth call",
`<><?xml?><ROOT><AAA></AAA><ZZZ><BBB>b5</BBB></ZZZ></ROOT></>`,
`<?xml?><ROOT><AAA></AAA><ZZZ><BBB>b5</BBB></ZZZ></ROOT>`,
findRoot(n))

_, err = sp.Read()
Expand Down Expand Up @@ -431,7 +431,7 @@ func TestStreamParser_Success2(t *testing.T) {
t.Fatal(err.Error())
}
testOutputXML(t, "first call result", `<CCC>c1</CCC>`, n)
testOutputXML(t, "doc after first call", `<><?xml?><AAA><CCC>c1</CCC></AAA></>`, findRoot(n))
testOutputXML(t, "doc after first call", `<?xml?><AAA><CCC>c1</CCC></AAA>`, findRoot(n))

// Second Read() should return d1
n, err = sp.Read()
Expand All @@ -440,7 +440,7 @@ func TestStreamParser_Success2(t *testing.T) {
}
testOutputXML(t, "second call result", `<DDD>d1</DDD>`, n)
testOutputXML(t, "doc after second call",
`<><?xml?><AAA><BBB>b1</BBB><DDD>d1</DDD></AAA></>`, findRoot(n))
`<?xml?><AAA><BBB>b1</BBB><DDD>d1</DDD></AAA>`, findRoot(n))

// Third call should return c2
n, err = sp.Read()
Expand All @@ -449,7 +449,7 @@ func TestStreamParser_Success2(t *testing.T) {
}
testOutputXML(t, "third call result", `<CCC>c2</CCC>`, n)
testOutputXML(t, "doc after third call",
`<><?xml?><AAA><BBB>b2</BBB><CCC>c2</CCC></AAA></>`, findRoot(n))
`<?xml?><AAA><BBB>b2</BBB><CCC>c2</CCC></AAA>`, findRoot(n))

_, err = sp.Read()
if err != io.EOF {
Expand Down

0 comments on commit 95ebf6b

Please sign in to comment.