Skip to content

Commit

Permalink
Merge pull request #42 from slotix/master
Browse files Browse the repository at this point in the history
fix for []string value type
  • Loading branch information
clbanning authored Jun 20, 2017
2 parents 6c2bf12 + 0a2b3e9 commit 39c1542
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
26 changes: 26 additions & 0 deletions xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,32 @@ func mapToXmlIndent(doIndent bool, s *string, key string, value interface{}, pp
}
}
return nil

case []string:
//quick fix for []string type
//[]string should be treated exaclty as []interface{}
if len(value.([]string)) == 0 {
if doIndent {
*s += p.padding + p.indent
}
*s += "<" + key
elen = 0
endTag = true
break
}
for _, v := range value.([]string) {
if doIndent {
p.Indent()
}
if err := mapToXmlIndent(doIndent, s, key, v, p); err != nil {
return err
}
if doIndent {
p.Outdent()
}
}
return nil

case nil:
// terminate the tag
if doIndent {
Expand Down
15 changes: 15 additions & 0 deletions xml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,20 @@ func TestXml_5(t *testing.T) {
fmt.Println("Xml_5, x :", string(x))
}


func TestXml_Strings(t *testing.T) {
mv := Map{"sometag": "some data", "strings": []string{"string1", "string2"}}

x, err := mv.Xml()
if err != nil {
t.Fatal("err:", err.Error())
}

fmt.Println("Xml_strings, mv:", mv)
fmt.Println("Xml_strings, x :", string(x))
}


func TestXmlWriter(t *testing.T) {
mv := Map{"tag1": "some data", "tag2": "more data", "boolean": true, "float": 3.14159625}
w := new(bytes.Buffer)
Expand All @@ -162,6 +176,7 @@ func TestXmlWriter(t *testing.T) {
fmt.Println("XmlWriter, b :", string(b))
}


// -------------------------- XML Handler test cases -------------------------

/* tested in bulk_test.go ...
Expand Down

0 comments on commit 39c1542

Please sign in to comment.