From 4f7417ecbc5f899dcc79ffac97cec6e8cc801b68 Mon Sep 17 00:00:00 2001 From: jim teeuwen Date: Fri, 30 Sep 2011 12:06:20 +0200 Subject: [PATCH] Minor improvements in Node.Bytes() implementation. Some test case tweaking. --- node.go | 4 ++-- test2.xml | 26 ++++++++++++-------------- xmlx_test.go | 8 ++++---- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/node.go b/node.go index c69742b..ee0d228 100644 --- a/node.go +++ b/node.go @@ -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) diff --git a/test2.xml b/test2.xml index d488157..d498fda 100644 --- a/test2.xml +++ b/test2.xml @@ -1,17 +1,15 @@ - - - moo - 123 - 321 - 1/1/2011 - - - moo - 123 - 321 - 1/1/2011 - - + + + john + doe + somename + someothername + + + some street 213 + Some City + + diff --git a/xmlx_test.go b/xmlx_test.go index fb2bc82..ebbc806 100644 --- a/xmlx_test.go +++ b/xmlx_test.go @@ -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)