-
Notifications
You must be signed in to change notification settings - Fork 789
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
94 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Package xml is a temporary way to convert XML to JSON. This package is only | ||
// necessary because github.com/clbanning/mxj has global configuration. If we | ||
// are able to configure a decoder etc at the API level then this package can be | ||
// removed. | ||
package xml | ||
|
||
import ( | ||
"encoding/xml" | ||
|
||
"github.com/clbanning/mxj" | ||
"golang.org/x/net/html/charset" | ||
) | ||
|
||
func init() { | ||
dec := xml.NewDecoder(nil) | ||
dec.Strict = false | ||
dec.CharsetReader = charset.NewReaderLabel | ||
mxj.CustomDecoder = dec | ||
} | ||
|
||
// ToMap parses a byte slice as XML and returns a generic structure that can be | ||
// serialized to JSON. | ||
func ToMap(xmlBytes []byte) (map[string]interface{}, error) { | ||
root, err := mxj.NewMapXml(xmlBytes) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return map[string]interface{}(root), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters