Minor improvements in Node.Bytes() implementation. Some test case tweaking.
This commit is contained in:
parent
2a2a591c08
commit
4f7417ecbc
4
node.go
4
node.go
|
@ -277,7 +277,7 @@ func (this *Node) String() (s string) {
|
||||||
func (this *Node) printRoot() []byte {
|
func (this *Node) printRoot() []byte {
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
for _, v := range this.Children {
|
for _, v := range this.Children {
|
||||||
b.WriteString(v.String())
|
b.Write(v.Bytes())
|
||||||
}
|
}
|
||||||
return b.Bytes()
|
return b.Bytes()
|
||||||
}
|
}
|
||||||
|
@ -323,7 +323,7 @@ func (this *Node) printElement() []byte {
|
||||||
b.WriteRune('>')
|
b.WriteRune('>')
|
||||||
|
|
||||||
for _, v := range this.Children {
|
for _, v := range this.Children {
|
||||||
b.WriteString(v.String())
|
b.Write(v.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
b.WriteString(this.Value)
|
b.WriteString(this.Value)
|
||||||
|
|
26
test2.xml
26
test2.xml
|
@ -1,17 +1,15 @@
|
||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<xml>
|
<xml>
|
||||||
<books>
|
<ns:user>
|
||||||
<book>
|
<ns:name>
|
||||||
<xdc:author>moo</xdc:author>
|
<ns:first>john</ns:first>
|
||||||
<xdc:price>123</xdc:price>
|
<ns:last>doe</ns:last>
|
||||||
<xdc:pages>321</xdc:pages>
|
<google:name>somename</google:name>
|
||||||
<xdc:date>1/1/2011</xdc:date>
|
<facebook:name>someothername</facebook:name>
|
||||||
</book>
|
</ns:name>
|
||||||
<book>
|
<ns:address>
|
||||||
<xdc:author>moo</xdc:author>
|
<ns:street>some street 213</ns:street>
|
||||||
<xdc:price>123</xdc:price>
|
<ns:city>Some City</ns:city>
|
||||||
<xdc:pages>321</xdc:pages>
|
</ns:address>
|
||||||
<xdc:date>1/1/2011</xdc:date>
|
</ns:user>
|
||||||
</book>
|
|
||||||
</books>
|
|
||||||
</xml>
|
</xml>
|
||||||
|
|
|
@ -28,9 +28,9 @@ func TestWildcard(t *testing.T) {
|
||||||
return
|
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))
|
t.Errorf("Wrong number of child elements. Expected 4, got %d.", len(list))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ func TestSave(t *testing.T) {
|
||||||
func TestNodeSearch(t *testing.T) {
|
func TestNodeSearch(t *testing.T) {
|
||||||
doc := New()
|
doc := New()
|
||||||
|
|
||||||
if err := doc.LoadFile("test.xml"); err != nil {
|
if err := doc.LoadFile("test1.xml"); err != nil {
|
||||||
t.Errorf("LoadFile(): %s", err)
|
t.Errorf("LoadFile(): %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ type Image struct {
|
||||||
|
|
||||||
func TestUnmarshal(t *testing.T) {
|
func TestUnmarshal(t *testing.T) {
|
||||||
doc := New()
|
doc := New()
|
||||||
err := doc.LoadFile("test.xml")
|
err := doc.LoadFile("test1.xml")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("LoadFile(): %s", err)
|
t.Errorf("LoadFile(): %s", err)
|
||||||
|
|
Loading…
Reference in New Issue