Search documentation of xmerl

# xmerl_xpath (xmerl v2.1.6)

View Source

Xpath 1.0 search implementation.

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

## Types

nodeEntity()
option_list()

Options to customize the behaviour of the XPath scanner.

parentList()
xPathString()

## Functions

string(String, Doc)

Equivalent to `string(String, Doc, [], Doc, [])`.

string(String, Doc, Options)

Equivalent to `string(String, Doc, [], Doc, Options)`.

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

Extract nodes from a parsed XML tree.

# Types

# nodeEntity()

(not exported)

    -type nodeEntity() ::
              xmerl:xmlElement() |
              xmerl:xmlAttribute() |
              xmerl:xmlText() |
              xmerl:xmlPI() |
              xmerl:xmlComment() |
              xmerl:xmlNsNode() |
              xmerl:xmlDocument().

# option_list()

(not exported)

    -type option_list() :: [{atom(), term()}].

Options to customize the behaviour of the XPath scanner.

Possible options are:

`{namespace, #xmlNamespace}`
  Set namespace nodes, from XmlNamspace, in xmlContext
`{namespace, Nodes}`
  Set namespace nodes in xmlContext.

# parentList()

(not exported)

    -type parentList() :: [{atom(), integer()}].

# xPathString()

(not exported)

    -type xPathString() :: string().

# Functions

# string(String, Doc)

    -spec string(String, Doc) -> [nodeEntity()] | Scalar
                    when
                        String :: xPathString(),
                        Doc :: nodeEntity(),
                        Scalar :: #xmlObj{type :: term(), value :: term()}.

Equivalent to `string(String, Doc, [], Doc, [])`.

# string(String, Doc, Options)

    -spec string(String, Doc, Options) -> [nodeEntity()] | Scalar
                    when
                        String :: xPathString(),
                        Doc :: nodeEntity(),
                        Options :: option_list(),
                        Scalar :: #xmlObj{type :: term(), value :: term()}.

Equivalent to `string(String, Doc, [], Doc, Options)`.

# string(String, Node, Parents, Doc, Options)

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

Extract nodes from a parsed XML tree.

Extracts the nodes from the parsed XML tree according the XPath `String`.

`Scalar` is an `#xmlObj{}` record record with the fields `type` and `value`, where `#xmlObj.type` is `boolean | number | string`.