Skip to content

Commit

Permalink
remove dependency on clbanning/mxj
Browse files Browse the repository at this point in the history
  • Loading branch information
clbanning committed Feb 2, 2021
1 parent 6fa35a3 commit 0f0a447
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
25 changes: 18 additions & 7 deletions anyxml.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@ in anyxml/examples/goofy_map.go.
package anyxml

import (
"bytes"
"encoding/xml"
"io"
"reflect"

// "github.com/clbanning/mxj"
"github.com/clbanning/mxj/v2"
)

// Default missingElementTag value.
Expand Down Expand Up @@ -131,8 +130,14 @@ func Xml(v interface{}, rootTag ...string) ([]byte, error) {
}

if xmlCheckIsValid {
if _, err = mxj.NewMapXml(b); err != nil {
return nil, err
d := xml.NewDecoder(bytes.NewReader(b))
for {
_, err = d.Token()
if err == io.EOF {
break
} else if err != nil {
return nil, err
}
}
}

Expand Down Expand Up @@ -200,8 +205,14 @@ func XmlIndent(v interface{}, prefix, indent string, rootTag ...string) ([]byte,
}

if xmlCheckIsValid {
if _, err = mxj.NewMapXml(b); err != nil {
return nil, err
d := xml.NewDecoder(bytes.NewReader(b))
for _, err = d.Token(); err != io.EOF; {
_, err = d.Token()
if err == io.EOF {
break
} else if err != nil {
return nil, err
}
}
}

Expand Down
1 change: 1 addition & 0 deletions isvalid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func TestXmlCheckIsValid(t *testing.T) {
fmt.Printf("%v\n", m)

XmlCheckIsValid()
defer XmlCheckIsValid()
if _, err := Xml(m); err == nil {
t.Fatal("Xml err: nil")
}
Expand Down
4 changes: 0 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ See mxj package documentation for caveats, etc.
Since some values, such as arrays, may require injecting tag labels to generate the XML, unmarshaling
the resultant XML is not necessarily symmetric, i.e., you cannot get the original value back without some manipulation.

<h4>Dependencies</h4>

import github.com/clbanning/mxj/v2

<h4>Documentation</h4>

http://godoc.org/github.com/clbanning/anyxml
Expand Down

0 comments on commit 0f0a447

Please sign in to comment.