Using XPath expressions

#include <x/xml/xpath.H>

rlock->get_xpath("body/p[1]")->to_node();

The parameter to a reader or a writer lock's get_xpath() is an XPath expression. x::xml::xpathescape() and x::xml::xpathescapestr() are available to help with referencing literal strings in the XPath expression. get_xpath() returns a x::xml::xpath representing the resulting nodeset from evaluating the expression against the current node the reader, or the writer, lock is positioned to. to_node() expects the nodeset containing exactly one node. It positions the lock, that created the x::xml::xpath, to the node.

Note

Each x::xml::xpath holds an internal reference on the underlying lock that created it, until the last reference to the object referred to by the x::xml::xpath goes out of, and it gets destroyed.

auto xpath=rlock->get_xpath("body/p");

for (size_t i=1, n=xpath->count(); i<=n; ++i)
{
    xpath->to_node(i);
}

count() returns the number of nodes in the nodeset. Passing an explicit node number to to_node() positions the lock to the given node in the nodeset.

Note

Nodes are numbered starting with node #1. A nodeset with three nodes consists of nodes #1, #2, and #3.

Note

to_node() throws an exception if the requested node no longer exists because it was remove()d.