mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-11 21:01:29 +00:00
added revisions to xmltojson based on source repo changes.
This commit is contained in:
parent
a6e2110f3d
commit
d0ef6a5293
2
utils/xmltojson/.gitignore
vendored
Normal file
2
utils/xmltojson/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
eqemu_config.xml
|
||||
eqemu_config.json
|
||||
@ -8,16 +8,15 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
xj "github.com/xackery/goxml2json"
|
||||
xj "github.com/basgys/goxml2json"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
var data []byte
|
||||
var sData string
|
||||
var buf *bytes.Buffer
|
||||
buf := &bytes.Buffer{}
|
||||
var buf2 bytes.Buffer
|
||||
xj.SetAttributePrefix("")
|
||||
|
||||
if data, err = ioutil.ReadFile("eqemu_config.xml"); err != nil {
|
||||
fmt.Println("Failed to open eqemu_config.xml:", err.Error())
|
||||
@ -26,10 +25,18 @@ func main() {
|
||||
|
||||
//detect malformed xml in eqemuconfig
|
||||
sData = strings.Replace(string(data), "<?xml version=\"1.0\">", "<?xml version=\"1.0\"?>", 1)
|
||||
r := strings.NewReader(sData)
|
||||
dec := xj.NewDecoder(r)
|
||||
root := &xj.Node{}
|
||||
if err = dec.DecodeWithCustomPrefixes(root, "", ""); err != nil {
|
||||
fmt.Println("Failed to decode eqemu_config.xml:", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
//convert xml to json
|
||||
if buf, err = xj.Convert(strings.NewReader(sData)); err != nil {
|
||||
fmt.Println("Failed to process eqemu_config.xml:", err.Error())
|
||||
enc := xj.NewEncoder(buf)
|
||||
err = enc.EncodeWithCustomPrefixes(root, "", "")
|
||||
if err != nil {
|
||||
fmt.Println("Failed to encode eqemu_config.xml:", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user