klyn.io.xml.xpath.DOMXPathEvaluator.selectSingleNode
method
public selectSingleNode(expression as String, contextNode as Node, resolver as XPathNSResolver = null) as Node throws XPathException, DOMException:
Description

Evaluates an XPath expression and returns its first matching node.

This is a Klyn convenience method for the common single-node lookup case. It returns null when no node matches.

Parameters
  • expression XPath expression selecting nodes.
  • contextNode Context node.
  • resolver Namespace resolver, or `null`.
Returns

First matching node, or null.

Throws
  • XPathException if the expression cannot be converted to a node set.
  • DOMException if the context node is invalid.
Example
node = DOMXPathEvaluator().selectSingleNode("/Spies/Spy[@id='007']", document)
if node is not null:
print(node.nodeName)