The Xpath implementation described in this article is used starting with version 8.4.10 when accessing certain nodes e.g. to fetch the right state-string from the XML body of an subscription notify.
Certain settings use a strip-down version of the Xpath-standard to point to certain elements in an XML.
Our Xpaths need always to start from the root (first token must be '/'). They usually point to a single element node (tag). An exception are the NotifyParsingRules of type array (since fw.version 8.7.3).
To save resources we do not allow Xpaths that introduce additional searches. The first time an element node description is found in an XML, it is used. So a path like "/*/subtree[@*='selected'] will search within the first element node of an XML for an element node named subtree whose first attribute has the value 'selected'.
The only axes supported are self and child.
Snom phones support:
- child or root
- pointing to element nodes of certain names
- /*, points to any tree
- /foo, points to a tree named foo that has no namespace
- /bar:foo, points to a tree named foo with namespace bar
- pointing to element nodes with certain attributes
- /*[@a], an element node that has an attribute named == a
- /a[@b][@c<42], an element node with the name a and an attribute named b present and an attribute named c whose value is a number smaller than 42
- pointing to element nodes with certain plain-text-content
- /a[.="c"], points to an element node like this: <a attr=whatEver>c</a>
- compare operators
- = eq != ne < lt <= le > gt >= ge, they work as string compares for text nodes and attribute values. When both operands on either side of the compare sign are numbers, numeric comparison is used.
- nested predicates and xpaths inside predicates
- min/max functions
- /bookstore/book[./price=max(/bookstore/book/price)]/title, the arguments of these functions may be xpaths that point to attributes. Also multiple arguments are supported like: min(/*[foo], 42, /bar.text())
- position indexes (limited)
- e.g.: /foo/* or /foo/*[last()-1] - be aware that the element node name must be * any and the position predicate must come first before any other predicates
- abbreviated and unabbreviated syntax
- e.g.: [attribute::name], [@name], /*/child::foo ...
Snom phones don't support:
- xpaths selecting anything else than element nodes (except inside min(), max() and predicates, where text() and attribute selections are also possible):
- /price/text() -> only allow price[.] or /price[.="3.99"]
- /price/@exchange -> only allow /price/* [@exchange]
- /bookstore[./book/attribute::price<0.01] -> is OK
- xpaths trying selecting the xy occurence of an element node with a certain name or otherwise limited subset of siblings of the current node:
- /author/*[@lang="engl"][last()] -> only allowed /*/*[last()][@lang="engl"]
- xpaths making us search:
- //book -> only allow access to child nodes starting from root or current node /*/book[./author/text()="Douglas Admas"]
- xpaths where name space or post-namespace is any while the other is not:
- /my:* or /*:foo -> only allow /* or /my:foo