Skip to content

Commit

Permalink
issue #90 - part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
clbanning committed Mar 8, 2021
1 parent 13245dc commit 792145c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
8 changes: 4 additions & 4 deletions anyxml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func TestNilMap(t *testing.T) {

func TestNilValue(t *testing.T) {
val := map[string]interface{}{"toplevel": nil}
checkval := "<root><toplevel><nil></toplevel></root>"
checkval := "<root><toplevel/></root>"

XmlDefaultEmptyElemSyntax()
xmlout, err := AnyXml(val, "root")
Expand All @@ -171,7 +171,7 @@ func TestNilValue(t *testing.T) {
}

checkval = ` <root>
<toplevel><nil></toplevel>
<toplevel/>
</root>`
xmlout, err = AnyXmlIndent(val, " ", " ", "root")
if err != nil {
Expand All @@ -183,7 +183,7 @@ func TestNilValue(t *testing.T) {
}

XmlGoEmptyElemSyntax()
checkval = "<root><toplevel><nil></toplevel></root>"
checkval = "<root><toplevel></toplevel></root>"
xmlout, err = AnyXml(val, "root")
if err != nil {
t.Fatal(err)
Expand All @@ -194,7 +194,7 @@ func TestNilValue(t *testing.T) {
}

checkval = ` <root>
<toplevel><nil></toplevel>
<toplevel></toplevel>
</root>`
xmlout, err = AnyXmlIndent(val, " ", " ", "root")
if err != nil {
Expand Down
9 changes: 5 additions & 4 deletions isvalid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ func TestXmlCheckIsValid(t *testing.T) {
t.Fatal("NewMapJson err;", err)
}
fmt.Printf("%v\n", m)
if _, err = m.Xml(); err == nil {
t.Fatal("Xml err: nil")
if b, err := m.Xml(); err != nil {
fmt.Println("m:", string(b))
t.Fatal("Xml err:", err)
}
if _, err = m.XmlIndent("", " "); err == nil {
t.Fatal("XmlIndent err: nil")
if _, err = m.XmlIndent("", " "); err != nil {
t.Fatal("XmlIndent err:", nil)
}

ms, err := NewMapXmlSeq([]byte(`<doc><elem>element</elem></doc>`))
Expand Down
6 changes: 6 additions & 0 deletions xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,12 @@ func xmlToMapParser(skey string, a []xml.Attr, p *xml.Decoder, r bool) (map[stri
} else {
n[skey] = "" // empty element
}
} else if len(n) == 1 && len(na) > 0 {
// it's a simple element w/ no attributes w/ subelements
for _, v := range n {
na["#text"] = v
}
n[skey] = na
}
return n, nil
case xml.CharData:
Expand Down

0 comments on commit 792145c

Please sign in to comment.