Browse Source

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

master
jim teeuwen 11 years ago
parent
commit
4f7417ecbc
  1. 4
      node.go
  2. 26
      test2.xml
  3. 8
      xmlx_test.go

4
node.go

@ -277,7 +277,7 @@ func (this *Node) String() (s string) { @@ -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 { @@ -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)

26
test2.xml

@ -1,17 +1,15 @@ @@ -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>

8
xmlx_test.go

@ -28,9 +28,9 @@ func TestWildcard(t *testing.T) { @@ -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) { @@ -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 { @@ -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)

Loading…
Cancel
Save