You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
409 B
26 lines
409 B
2 years ago
|
package xml2json
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"io"
|
||
|
)
|
||
|
|
||
|
// Convert converts the given XML document to JSON
|
||
|
func Convert(r io.Reader) (*bytes.Buffer, error) {
|
||
|
// Decode XML document
|
||
|
root := &Node{}
|
||
|
err := NewDecoder(r).Decode(root)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
// Then encode it in JSON
|
||
|
buf := new(bytes.Buffer)
|
||
|
err = NewEncoder(buf).Encode(root)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
return buf, nil
|
||
|
}
|