Am I correct in thinking an XPath expression can only point to/select either an element or an element attribute?
According to the XPath documentation at W3C:
An expression is evaluated to yield an object, which has one of the following four basic types:
- node-set (an unordered collection of nodes without duplicates)
- boolean (true or false)
- number (a floating-point number)
- string (a sequence of UCS characters)
The nodes are elements of the document tree, so they can include element nodes, attribute nodes and text nodes. And note that an XPath expression can select a number of nodes - i.e. a number of elements - not just a single one.
Some examples:
//monkey - will select all <monkey> elements in the document, a node-setcount(//monkey) - will return the count of all <monkey> elements, a numbercontains("mouse", "cat") - will return false, a boolean(//monkey)[0]/text() - will return the text from the first <monkey> element, a stringIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With