xmerl_xpath(3)
π 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, fromXmlNamspace, inxmlContext.{namespace, Nodes}β sets namespace nodes inxmlContext.
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
- ubuntu stonking: erlang-doc 1:29.0.6+dfsg-1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms