Minor improvements in Node.Bytes() implementation. Some test case tweaking.

This commit is contained in:
jim teeuwen 2011-09-30 12:06:20 +02:00
parent 2a2a591c08
commit 4f7417ecbc
3 changed files with 18 additions and 20 deletions

View File

@ -277,7 +277,7 @@ func (this *Node) String() (s string) {
func (this *Node) printRoot() []byte {
var b bytes.Buffer
for _, v := range this.Children {
b.WriteString(v.String())
b.Write(v.Bytes())
}
return b.Bytes()
}
@ -323,7 +323,7 @@ func (this *Node) printElement() []byte {
b.WriteRune('>')
for _, v := range this.Children {
b.WriteString(v.String())
b.Write(v.Bytes())
}
b.WriteString(this.Value)

View File

@ -1,17 +1,15 @@
<?xml version="1.0"?>
<xml>
<books>
<book>
<xdc:author>moo</xdc:author>
<xdc:price>123</xdc:price>
<xdc:pages>321</xdc:pages>
<xdc:date>1/1/2011</xdc:date>
</book>
<book>
<xdc:author>moo</xdc:author>
<xdc:price>123</xdc:price>
<xdc:pages>321</xdc:pages>
<xdc:date>1/1/2011</xdc:date>
</book>
</books>
<ns:user>
<ns:name>
<ns:first>john</ns:first>
<ns:last>doe</ns:last>
<google:name>somename</google:name>
<facebook:name>someothername</facebook:name>
</ns:name>
<ns:address>
<ns:street>some street 213</ns:street>
<ns:city>Some City</ns:city>
</ns:address>
</ns:user>
</xml>

View File

@ -28,9 +28,9 @@ func TestWildcard(t *testing.T) {
return
}
list := doc.SelectNodes("xdc", "*")
list := doc.SelectNodes("ns", "*")
if len(list) != 8 {
if len(list) != 1 {
t.Errorf("Wrong number of child elements. Expected 4, got %d.", len(list))
return
}
@ -67,7 +67,7 @@ func TestSave(t *testing.T) {
func TestNodeSearch(t *testing.T) {
doc := New()
if err := doc.LoadFile("test.xml"); err != nil {
if err := doc.LoadFile("test1.xml"); err != nil {
t.Errorf("LoadFile(): %s", err)
return
}
@ -95,7 +95,7 @@ type Image struct {
func TestUnmarshal(t *testing.T) {
doc := New()
err := doc.LoadFile("test.xml")
err := doc.LoadFile("test1.xml")
if err != nil {
t.Errorf("LoadFile(): %s", err)