檢視原始碼 xmerl_xpath (xmerl v2.1)
Xpath 1.0 搜尋實作。
xmerl_xpath
模組處理整個 XPath 1.0 規範。XPath 表達式通常出現在 XML 屬性中,用於尋址 XML 文件的一部分。語法定義在 xmerl_xpath_parse.yrl
中。核心函數定義在 xmerl_xpath_pred.erl
中。
一些用於除錯 XPath 解析器的實用 Shell 命令
c(xmerl_xpath_scan).
yecc:yecc("xmerl_xpath_parse.yrl", "xmerl_xpath_parse", true, []).
c(xmerl_xpath_parse).
xmerl_xpath_parse:parse(xmerl_xpath_scan:tokens("position() > -1")).
xmerl_xpath_parse:parse(xmerl_xpath_scan:tokens("5 * 6 div 2")).
xmerl_xpath_parse:parse(xmerl_xpath_scan:tokens("5 + 6 mod 2")).
xmerl_xpath_parse:parse(xmerl_xpath_scan:tokens("5 * 6")).
xmerl_xpath_parse:parse(xmerl_xpath_scan:tokens("-----6")).
xmerl_xpath_parse:parse(xmerl_xpath_scan:tokens("parent::node()")).
xmerl_xpath_parse:parse(xmerl_xpath_scan:tokens("descendant-or-self::node()")).
xmerl_xpath_parse:parse(xmerl_xpath_scan:tokens("parent::processing-instruction('foo')")).
摘要
類型
-type nodeEntity() :: xmerl:xmlElement() | xmerl:xmlAttribute() | xmerl:xmlText() | xmerl:xmlPI() | xmerl:xmlComment() | xmerl:xmlNsNode() | xmerl:xmlDocument().
自訂 XPath 掃描器行為的選項。
可能的選項為
{namespace, #xmlNamespace}
- 在 xmlContext 中,從 XmlNamspace 設定命名空間節點
{namespace, Nodes}
- 在 xmlContext 中設定命名空間節點。
-type xPathString() :: string().
函式
-spec string(String, Doc) -> _ when String :: xPathString(), Doc :: nodeEntity().
-spec string(String, Doc, Options) -> _ when String :: xPathString(), Doc :: nodeEntity(), Options :: option_list().
-spec string(String, Node, Parents, Doc, Options) -> [nodeEntity()] | Scalar when String :: xPathString(), Node :: nodeEntity(), Parents :: parentList(), Doc :: nodeEntity(), Options :: option_list(), Scalar :: #xmlObj{type :: term(), value :: term()}.
從已解析的 XML 樹中提取節點。
根據 XPath String
從已解析的 XML 樹中提取節點。
Scalar
是一個 #xmlObj{}
記錄,具有欄位 type
和 value
,其中 #xmlObj.type
是 boolean | number | string
。