xmlquery: github.com/antchfx/xmlquery Index | Files

package xmlquery

import "github.com/antchfx/xmlquery"

Package xmlquery provides extract data from XML documents using XPath expression.


Package Files

cache.go node.go query.go


var DisableSelectorCache = false

DisableSelectorCache will disable caching for the query selector if value is true.

var SelectorCacheMaxEntries = 50

SelectorCacheMaxEntries allows how many selector object can be caching. Default is 50. Will disable caching if SelectorCacheMaxEntries <= 0.

func FindEach Uses

func FindEach(top *Node, expr string, cb func(int, *Node))

FindEach searches the html.Node and calls functions cb. Important: this method has deprecated, recommend use for .. = range Find(){}.

func FindEachWithBreak Uses

func FindEachWithBreak(top *Node, expr string, cb func(int, *Node) bool)

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(){}.

type Node Uses

type Node struct {
    Parent, FirstChild, LastChild, PrevSibling, NextSibling *Node

    Type         NodeType
    Data         string
    Prefix       string
    NamespaceURI string
    Attr         []xml.Attr
    // 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 Find Uses

func Find(top *Node, expr string) []*Node

Find is like QueryAll but it will panics if the `expr` is not a valid XPath expression. See `QueryAll()` function.

func FindOne Uses

func FindOne(top *Node, expr string) *Node

FindOne is like Query but it will panics if the `expr` is not a valid XPath expression. See `Query()` function.

func LoadURL Uses

func LoadURL(url string) (*Node, error)

LoadURL loads the XML document from the specified URL.

func Parse Uses

func Parse(r io.Reader) (*Node, error)

Parse returns the parse tree for the XML from the given Reader.

func Query Uses

func Query(top *Node, expr string) (*Node, error)

Query searches the XML Node that matches by the specified XPath expr, and returns first element of matched.

func QueryAll Uses

func QueryAll(top *Node, expr string) ([]*Node, error)

QueryAll searches the XML Node that matches by the specified XPath expr. Return an error if the expression `expr` cannot be parsed.

func QuerySelector Uses

func QuerySelector(top *Node, selector *xpath.Expr) *Node

QuerySelector returns the first matched XML Node by the specified XPath selector.

func QuerySelectorAll Uses

func QuerySelectorAll(top *Node, selector *xpath.Expr) []*Node

QuerySelectorAll searches all of the XML Node that matches the specified XPath selectors.

func (*Node) InnerText Uses

func (n *Node) InnerText() string

InnerText returns the text between the start and end tags of the object.

func (*Node) OutputXML Uses

func (n *Node) OutputXML(self bool) string

OutputXML returns the text that including tags name.

func (*Node) SelectAttr Uses

func (n *Node) SelectAttr(name string) string

SelectAttr returns the attribute value with the specified name.

func (*Node) SelectElement Uses

func (n *Node) SelectElement(name string) *Node

SelectElement finds child elements with the specified name.

func (*Node) SelectElements Uses

func (n *Node) SelectElements(name string) []*Node

SelectElements finds child elements with the specified name.

type NodeNavigator Uses

type NodeNavigator struct {
    // contains filtered or unexported fields

func CreateXPathNavigator Uses

func CreateXPathNavigator(top *Node) *NodeNavigator

CreateXPathNavigator creates a new xpath.NodeNavigator for the specified html.Node.

func (*NodeNavigator) Copy Uses

func (x *NodeNavigator) Copy() xpath.NodeNavigator

func (*NodeNavigator) Current Uses

func (x *NodeNavigator) Current() *Node

func (*NodeNavigator) LocalName Uses

func (x *NodeNavigator) LocalName() string

func (*NodeNavigator) MoveTo Uses

func (x *NodeNavigator) MoveTo(other xpath.NodeNavigator) bool

func (*NodeNavigator) MoveToChild Uses

func (x *NodeNavigator) MoveToChild() bool

func (*NodeNavigator) MoveToFirst Uses

func (x *NodeNavigator) MoveToFirst() bool

func (*NodeNavigator) MoveToNext Uses

func (x *NodeNavigator) MoveToNext() bool

func (*NodeNavigator) MoveToNextAttribute Uses

func (x *NodeNavigator) MoveToNextAttribute() bool

func (*NodeNavigator) MoveToParent Uses

func (x *NodeNavigator) MoveToParent() bool

func (*NodeNavigator) MoveToPrevious Uses

func (x *NodeNavigator) MoveToPrevious() bool

func (*NodeNavigator) MoveToRoot Uses

func (x *NodeNavigator) MoveToRoot()

func (*NodeNavigator) NamespaceURL Uses

func (x *NodeNavigator) NamespaceURL() string

func (*NodeNavigator) NodeType Uses

func (x *NodeNavigator) NodeType() xpath.NodeType

func (*NodeNavigator) Prefix Uses

func (x *NodeNavigator) Prefix() string

func (*NodeNavigator) String Uses

func (x *NodeNavigator) String() string

func (*NodeNavigator) Value Uses

func (x *NodeNavigator) Value() string

type NodeType Uses

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...> ).
    // ElementNode is an element (for example, <item> ).
    // TextNode is the text content of a node.
    // CharDataNode node <![CDATA[content]]>
    // CommentNode a comment (for example, <!-- my comment --> ).
    // AttributeNode is an attribute of element.

Package xmlquery imports 11 packages (graph) and is imported by 28 packages. Updated 2020-04-25. Refresh now. Tools for package owners.