Documentation
¶
Overview ¶
Package dom provides document object model for xml.
It does not strictly follow DOM interfaces, but has everything needed for xml processing library.
Example ¶
package main
import (
"bytes"
"encoding/xml"
"fmt"
"strings"
"github.com/santhosh-tekuri/dom"
)
func main() {
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>
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Comment ¶
A Comment represents an XML comment of the form <!--comment-->. The bytes do not include the <!-- and --> comment markers.
type Document ¶
type Document struct {
ChildNodes []Node
}
A Document represents XML Document.
func OwnerDocument ¶
OwnerDocument returns The Document object associated with given node.
func (*Document) RootElement ¶
RootElement returns the root element of the document
type Element ¶
type Element struct {
ParentNode Parent
*Name
NSDecl map[string]string
Attrs []*Attr
ChildNodes []Node
}
An Element represents an XML element.
func (*Element) GetAttr ¶
GetAttr returns the attribute with given uri and local. It returns null, if attribute is not found.
func (*Element) ResolvePrefix ¶
ResolvePrefix returns the URI bound to given prefix. The second return value tells whether prefix is bound or not.
type Node ¶
A Node is an interface holding one of the types: *Document, *Element, *Text, *Comment, *ProcInst, *Attr or *Namespace.