Package dom provides document object model for xml.
It does not strictly follow DOM interfaces, but has everything needed for xml processing library.
str := `
<developer xmlns="www.jroller.com/santhosh/">
<name>Santhosh Kumar Tekuri</name>
<email>santhosh.tekuri@gmail.com</email>
</developer>
`
doc, err := dom.Unmarshal(xml.NewDecoder(strings.NewReader(str)))
if err != nil {
fmt.Println(err)
return
}
root := doc.RootElement()
fmt.Printf("rootElement: {%s}%s\n", root.URI, root.Local)
buf := new(bytes.Buffer)
if err = dom.Marshal(doc, buf); err != nil {
fmt.Println(err)
return
}
fmt.Printf("xml:\n%s", buf.String())
Output:
rootElement: {www.jroller.com/santhosh/}developer
xml:
<developer xmlns="www.jroller.com/santhosh/">
<name>Santhosh Kumar Tekuri</name>
<email>santhosh.tekuri@gmail.com</email>
</developer>