xmerl_xpath(3)

πŸ“¦
version 29.0.6 Β· 3 versions
, in ubuntu stonking

πŸ’– xmerl_xpath β€” the Erlang module definition, but make it make sense ✨

okay bestie, welcome to xmerl_xpath(3) β€” yes that's the Erlang Module Definition, and yes she's iconic.


🌸 NAME 🌸

xmerl_xpath β€” Xpath 1.0 search implementation. that's it, that's the gig. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so like, the xmerl_xpath module handles the entire XPath 1.0 spec. every last bit of it. no cap. πŸ”₯

XPath expressions typically show up inside XML attributes, and their whole job is addressing parts of an XML document. the grammar lives in xmerl_xpath_parse.yrl. the core functions live in xmerl_xpath_pred.erl. that's the lore. πŸ“œ

some useful shell commands for debugging the XPath parser β€” copy these exactly, they're precious 🫢

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

πŸŽ€ DATA TYPES πŸŽ€

nodeEntity()

the way this one is a whole little union type 😭 she can be any of these:

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

option_list()

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

these are the options that customize the behaviour of the XPath scanner. queen of customization. πŸ‘‘

possible options are:

  • {namespace, #xmlNamespace} β€” sets namespace nodes, from XmlNamspace, in xmlContext.
  • {namespace, Nodes} β€” sets namespace nodes in xmlContext.

parentList()

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

xPathString()

xPathString() :: string().

⭐ FUNCTIONS ⭐

string(String, Node, Parents, Doc, Options) -> [nodeEntity()] | Scalar

with these types, okay, look at the when-clause, she's thorough:

String :: xPathString(),
Node :: nodeEntity(),
Parents :: parentList(),
Doc :: nodeEntity(),
Options :: option_list(),
Scalar :: #xmlObj{}.

extract nodes from a parsed XML tree. that's the mission, that's the vibe. 🌈

she extracts the nodes from the parsed XML tree according the XPath String. fr fr.

Scalar is an #xmlObj{} record with the fields type and value, where #xmlObj.type is boolean | number | string. yes literally those three. πŸ’€


reminder bestie: this module is doing the whole XPath 1.0 spec, so if something in your XPath expression is being weird, the parser files above are your besties for debugging. go peek at them. πŸ”

mwah πŸ’œ this little page is brought to you by Ericsson AB, version xmerl 2.2, and it's the xmerl_xpath(3) page, periodt. βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from