Documentation
¶
Overview ¶
Package xmlquery provides extract data from XML documents using XPath expression.
Index ¶
- func FindEach(top *Node, expr string, cb func(int, *Node))
- func FindEachWithBreak(top *Node, expr string, cb func(int, *Node) bool)
- type Node
- func (n *Node) AddAfter(sibling *Node)
- func (n *Node) AddBefore(sibling *Node)
- func (n *Node) AddChild(child *Node)
- func (n *Node) AddSibling(sibling *Node)
- func (n *Node) AppendAttr(key, val string)
- func (n *Node) DelAttr(key string) bool
- func (n *Node) DeleteMe()
- func (n *Node) GetAttr(key string) (string, bool)
- func (n *Node) GetAttrWithDefault(key, empty string) string
- func (n *Node) InnerText() string
- func (n *Node) NthChild() int
- func (n *Node) NthChildOfElem() int
- func (n *Node) OutputXML(self bool) string
- func (n *Node) OutputXMLToWriter(output io.Writer, pretty bool, self bool)
- func (n *Node) Reparent(new_parent *Node)
- func (n *Node) SelectAttr(name string) string
- func (n *Node) SelectElement(name string) *Node
- func (n *Node) SelectElements(name string) []*Node
- func (n *Node) SetAttr(key, val string) bool
- func (n *Node) String() string
- type NodeNavigator
- func (x *NodeNavigator) Copy() xpath.NodeNavigator
- func (x *NodeNavigator) Current() *Node
- func (x *NodeNavigator) LocalName() string
- func (x *NodeNavigator) MoveTo(other xpath.NodeNavigator) bool
- func (x *NodeNavigator) MoveToChild() bool
- func (x *NodeNavigator) MoveToFirst() bool
- func (x *NodeNavigator) MoveToNext() bool
- func (x *NodeNavigator) MoveToNextAttribute() bool
- func (x *NodeNavigator) MoveToParent() bool
- func (x *NodeNavigator) MoveToPrevious() bool
- func (x *NodeNavigator) MoveToRoot()
- func (x *NodeNavigator) NodeType() xpath.NodeType
- func (x *NodeNavigator) Prefix() string
- func (x *NodeNavigator) String() string
- func (x *NodeNavigator) Value() string
- type NodeType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindEach ¶
FindEach searches the html.Node and calls functions cb. Important: this method has deprecated, recommend use for .. = range Find(){}.
func FindEachWithBreak ¶
FindEachWithBreak functions the same as FindEach but allows you to break the loop by returning false from your callback function, cb. Important: this method has deprecated, recommend use for .. = range Find(){}.
Types ¶
type Node ¶
type Node struct {
Parent, FirstChild, LastChild, PrevSibling, NextSibling *Node
Type NodeType
Data string
Prefix string
NamespaceURI string
Attr []xml.Attr
// Application specific field that is never encoded to XML
Info interface{}
// contains filtered or unexported fields
}
A Node consists of a NodeType and some Data (tag name for element nodes, content for text) and are part of a tree of Nodes.
func FindOne ¶
FindOne searches the Node that matches by the specified XPath expr, and returns first element of matched.
func (*Node) AddSibling ¶ added in v1.1.0
func (*Node) AppendAttr ¶ added in v1.1.2
Useful for the @class HTML attribute.
func (*Node) DelAttr ¶ added in v1.1.0
Returns true if the attribute existed and was deleted; false otherwise.
func (*Node) DeleteMe ¶ added in v1.1.0
func (n *Node) DeleteMe()
Dereference this node from others so GC can delete them. Also fixes pointers of other nodes.
func (*Node) GetAttrWithDefault ¶ added in v1.1.0
func (*Node) NthChildOfElem ¶ added in v1.1.0
func (*Node) OutputXMLToWriter ¶ added in v1.1.0
Same as OutputXML.
func (*Node) SelectAttr ¶
SelectAttr returns the attribute value with the specified name.
func (*Node) SelectElement ¶
SelectElement finds child elements with the specified name.
func (*Node) SelectElements ¶
SelectElements finds child elements with the specified name.
type NodeNavigator ¶
type NodeNavigator struct {
// contains filtered or unexported fields
}
func CreateXPathNavigator ¶
func CreateXPathNavigator(top *Node) *NodeNavigator
CreateXPathNavigator creates a new xpath.NodeNavigator for the specified html.Node.
func (*NodeNavigator) Copy ¶
func (x *NodeNavigator) Copy() xpath.NodeNavigator
func (*NodeNavigator) Current ¶
func (x *NodeNavigator) Current() *Node
func (*NodeNavigator) LocalName ¶
func (x *NodeNavigator) LocalName() string
func (*NodeNavigator) MoveTo ¶
func (x *NodeNavigator) MoveTo(other xpath.NodeNavigator) bool
func (*NodeNavigator) MoveToChild ¶
func (x *NodeNavigator) MoveToChild() bool
func (*NodeNavigator) MoveToFirst ¶
func (x *NodeNavigator) MoveToFirst() bool
func (*NodeNavigator) MoveToNext ¶
func (x *NodeNavigator) MoveToNext() bool
func (*NodeNavigator) MoveToNextAttribute ¶
func (x *NodeNavigator) MoveToNextAttribute() bool
func (*NodeNavigator) MoveToParent ¶
func (x *NodeNavigator) MoveToParent() bool
func (*NodeNavigator) MoveToPrevious ¶
func (x *NodeNavigator) MoveToPrevious() bool
func (*NodeNavigator) MoveToRoot ¶
func (x *NodeNavigator) MoveToRoot()
func (*NodeNavigator) NodeType ¶
func (x *NodeNavigator) NodeType() xpath.NodeType
func (*NodeNavigator) Prefix ¶
func (x *NodeNavigator) Prefix() string
func (*NodeNavigator) String ¶
func (x *NodeNavigator) String() string
func (*NodeNavigator) Value ¶
func (x *NodeNavigator) Value() string
type NodeType ¶
type NodeType uint
A NodeType is the type of a Node.
const ( // DocumentNode is a document object that, as the root of the document tree, // provides access to the entire XML document. DocumentNode NodeType = iota // DeclarationNode is the document type declaration, indicated by the following // tag (for example, <!DOCTYPE...> ). DeclarationNode // ElementNode is an element (for example, <item> ). ElementNode // TextNode is the text content of a node. TextNode // CommentNode a comment (for example, <!-- my comment --> ). CommentNode // AttributeNode is an attribute of element. AttributeNode )