Documentation ¶
Overview ¶
Package xmlnode provides a hierarchical node representation of XML documents. This package wraps encoding/xml and can be used instead of it.
Each node has an underlying concrete type, but calling all functions is legal. For example, here is how you can traverse the node tree:
func traverse(n Node) { // Text() returns an empty string for non-text nodes. doSomeTextSearch(n.Text()) // Children() returns nil for non-parent nodes. for _, child := range n.Children() { traverse(child) } }
Index ¶
Constants ¶
const ( Root = iota Tag Text Comment ProcInst Directive )
Possible return values of Type().
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Node ¶
type Node interface { // Parent of the current node. Nil for root node. Parent() Node // Tag name of tag nodes of the form <tagname>...</tagname>. Empty for // other node types. TagName() string // Attributes of tag nodes. Nil for other node types. Attr() []*xml.Attr // Child nodes of root and tag nodes. Nil for other node types. Children() []Node // Text data of text nodes. Empty for other node types. Text() string // Comment data of comments of the form <!--comment-->. Does not include the // <!-- and --> markers. Empty for other node types. Comment() string // Target of processing instructions of the form <?target inst?>. // Empty for other node types. Target() string // Instruction of processing instructions of the form <?target inst?>. // Empty for other node types. Inst() string // Directive of the form <!directive>. Does not include the <! and > // markers. Empty for other node types. Directive() string // Type of this node. Returns one of: Root, Tag, Text, Comment, ProcInst // or Directive. Type() int }
A Node represents a single XML node. Can be one of: Root, Tag, Text, Comment, ProcInst or Directive.
String methods return empty strings when called on a non-relevant node. For example, calling TagName() on a Text node or vise versa. The Children() method returns nil for non Tag or Root nodes. The Attr() method returns nil for non Tag nodes.
Parent node is nil only in Root.