View Source xmerl_xpath (xmerl v1.4)

The xmerl_xpath module handles the entire XPath 1.0 spec. XPath expressions typically occur in XML attributes and are used to address parts of an XML document. The grammar is defined in xmerl_xpath_parse.yrl. The core functions are defined in xmerl_xpath_pred.erl.

Some useful shell commands for debugging the XPath parser

 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')")).

Summary

Functions

Extracts the nodes from the parsed XML tree according to XPath. xmlObj is a record with fields type and value, where type is boolean | number | string

Types

Link to this type

docEntity()

View Source (not exported)
-type docEntity() :: #xmlDocument{content :: term()} | [docNodes()].
Link to this type

docNodes()

View Source (not exported)
-type docNodes() ::
    #xmlElement{name :: term(),
                expanded_name :: term(),
                nsinfo :: term(),
                namespace :: term(),
                parents :: term(),
                pos :: term(),
                attributes :: term(),
                content :: term(),
                language :: term(),
                xmlbase :: term(),
                elementdef :: term()} |
    #xmlAttribute{name :: term(),
                  expanded_name :: term(),
                  nsinfo :: term(),
                  namespace :: term(),
                  parents :: term(),
                  pos :: term(),
                  language :: term(),
                  value :: term(),
                  normalized :: term()} |
    #xmlText{parents :: term(),
             pos :: term(),
             language :: term(),
             value :: term(),
             type :: term()} |
    #xmlPI{name :: term(), parents :: term(), pos :: term(), value :: term()} |
    #xmlComment{parents :: term(), pos :: term(), language :: term(), value :: term()} |
    #xmlNsNode{parents :: term(), pos :: term(), prefix :: term(), uri :: term()}.
Link to this type

nodeEntity()

View Source (not exported)
-type nodeEntity() ::
    #xmlElement{name :: term(),
                expanded_name :: term(),
                nsinfo :: term(),
                namespace :: term(),
                parents :: term(),
                pos :: term(),
                attributes :: term(),
                content :: term(),
                language :: term(),
                xmlbase :: term(),
                elementdef :: term()} |
    #xmlAttribute{name :: term(),
                  expanded_name :: term(),
                  nsinfo :: term(),
                  namespace :: term(),
                  parents :: term(),
                  pos :: term(),
                  language :: term(),
                  value :: term(),
                  normalized :: term()} |
    #xmlText{parents :: term(),
             pos :: term(),
             language :: term(),
             value :: term(),
             type :: term()} |
    #xmlPI{name :: term(), parents :: term(), pos :: term(), value :: term()} |
    #xmlComment{parents :: term(), pos :: term(), language :: term(), value :: term()} |
    #xmlNsNode{parents :: term(), pos :: term(), prefix :: term(), uri :: term()} |
    #xmlDocument{content :: term()}.
Link to this type

option_list()

View Source (not exported)
-type option_list() :: [{atom(), term()}].
Link to this type

parentList()

View Source (not exported)
-type parentList() :: [{atom(), integer()}].
Link to this type

xPathString()

View Source (not exported)
-type xPathString() :: string().

Functions

Equivalent to string(Str, Doc, []).

Equivalent to string(Str, Doc, [], Doc, Options).

Link to this function

string(Str, Node, Parents, Doc, Options)

View Source
-spec string(Str, Node, Parents, Doc, Options) -> docEntity() | Scalar
          when
              Str :: xPathString(),
              Node :: nodeEntity(),
              Parents :: parentList(),
              Doc :: nodeEntity(),
              Options :: option_list(),
              Scalar :: #xmlObj{type :: term(), value :: term()}.

Extracts the nodes from the parsed XML tree according to XPath. xmlObj is a record with fields type and value, where type is boolean | number | string