Using XPath expressions

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

The parameter to a reader lock's get_xpath() is an XPath expression. get_xpath() returns a x::xml::doc::base::xpath representing the resulting nodeset from evaluating the expression against the current node the reader lock is positioned to. to_node() expects the nodeset containing exactly one node, and it positions the reader lock, that created the x::xml::doc::base::xpath, to the node.

Note

Each x::xml::doc::base::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::doc::base::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.

bool flag=xpath->as_bool();

double number=xpath->as_number();

std::string string=xpath->as_string();

as_bool(), as_number(), and as_string() return the value of the XPath nodeset expressed as the corresponding data type.