xpath

XPath package for Golang, supported HTML, XML, JSON query.

Github星跟蹤圖

XPath

GoDoc
Coverage Status
Build Status
Go Report Card

XPath is Go package provides selecting nodes from XML, HTML or other documents using XPath expression.

Implementation

  • htmlquery - an XPath query package for HTML document

  • xmlquery - an XPath query package for XML document.

  • jsonquery - an XPath query package for JSON document

Supported Features

The basic XPath patterns.

The basic XPath patterns cover 90% of the cases that most stylesheets will need.

  • node : Selects all child elements with nodeName of node.

  • * : Selects all child elements.

  • @attr : Selects the attribute attr.

  • @* : Selects all attributes.

  • node() : Matches an org.w3c.dom.Node.

  • text() : Matches a org.w3c.dom.Text node.

  • comment() : Matches a comment.

  • . : Selects the current node.

  • .. : Selects the parent of current node.

  • / : Selects the document node.

  • a[expr] : Select only those nodes matching a which also satisfy the expression expr.

  • a[n] : Selects the nth matching node matching a When a filter's expression is a number, XPath selects based on position.

  • a/b : For each node matching a, add the nodes matching b to the result.

  • a//b : For each node matching a, add the descendant nodes matching b to the result.

  • //b : Returns elements in the entire document matching b.

  • a, b : All nodes matching a or b, union operation(not boolean or).

  • (a, b, c) : Evaluates each of its operands and concatenates the resulting sequences, in order, into a single result sequence

Node Axes

  • child::* : The child axis selects children of the current node.

  • descendant::* : The descendant axis selects descendants of the current node. It is equivalent to '//'.

  • descendant-or-self::* : Selects descendants including the current node.

  • attribute::* : Selects attributes of the current element. It is equivalent to @*

  • following-sibling::* : Selects nodes after the current node.

  • preceding-sibling::* : Selects nodes before the current node.

  • following::* : Selects the first matching node following in document order, excluding descendants.

  • preceding::* : Selects the first matching node preceding in document order, excluding ancestors.

  • parent::* : Selects the parent if it matches. The '..' pattern from the core is equivalent to 'parent::node()'.

  • ancestor::* : Selects matching ancestors.

  • ancestor-or-self::* : Selects ancestors including the current node.

  • self::* : Selects the current node. '.' is equivalent to 'self::node()'.

Expressions

The gxpath supported three types: number, boolean, string.

  • path : Selects nodes based on the path.

  • a = b : Standard comparisons.

    • a = b True if a equals b.
    • a != b True if a is not equal to b.
    • a < b True if a is less than b.
    • a <= b True if a is less than or equal to b.
    • a > b True if a is greater than b.
    • a >= b True if a is greater than or equal to b.
  • a + b : Arithmetic expressions.

    • - a Unary minus
    • a + b Add
    • a - b Substract
    • a * b Multiply
    • a div b Divide
    • a mod b Floating point mod, like Java.
  • a or b : Boolean or operation.

  • a and b : Boolean and operation.

  • (expr) : Parenthesized expressions.

  • fun(arg1, ..., argn) : Function calls:, Function, Supported, ---, ---, boolean(), ✓, ceiling(), ✓, choose(), ✗, concat(), ✓, contains(), ✓, count(), ✓, current(), ✗, document(), ✗, element-available(), ✗, ends-with(), ✓, false(), ✓, floor(), ✓, format-number(), ✗, function-available(), ✗, generate-id(), ✗, id(), ✗, key(), ✗, lang(), ✗, last(), ✓, local-name(), ✓, name(), ✓, namespace-uri(), ✓, normalize-space(), ✓, not(), ✓, number(), ✓, position(), ✓, replace(), ✓, round(), ✓, starts-with(), ✓, string(), ✓, string-length(), ✓, substring(), ✓, substring-after(), ✓, substring-before(), ✓, sum(), ✓, system-property(), ✗, translate(), ✓, true(), ✓, unparsed-entity-url(), ✗, Changelogs
    ===

2019-03-19

  • optimize XPath , operation performance. #33. Tips: suggest split into multiple subquery if you have a lot of , operations.

2019-01-29

  • improvement normalize-space function. #32

2018-12-07

  • supports XPath 2.0 Sequence expressions. #30 by @minherz.

主要指標

概覽
名稱與所有者antchfx/xpath
主編程語言Go
編程語言Go (語言數: 1)
平台
許可證MIT License
所有者活动
創建於2016-10-09 05:51:24
推送於2025-04-21 13:36:04
最后一次提交2025-04-21 21:35:58
發布數25
最新版本名稱v1.3.4 (發布於 )
第一版名稱v1.0.0 (發布於 )
用户参与
星數719
關注者數11
派生數91
提交數220
已啟用問題?
問題數80
打開的問題數15
拉請求數27
打開的拉請求數2
關閉的拉請求數7
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?