0

I spent the last week reading and re-reading the pugixml documentation and I can find no method of retrieving the PCDATA with xpath.

Please explain would I pull the text from title:

<html><head><title>Hello!</title></head></html>

Last time I asked this question the only answers I got referred to generic xpath queries, rather than specifically to the pugixml library functions. I've read the xpath documentation thoroughly, so don't worry about educating me about it.

Thanks.

user688579
  • 21
  • 1

2 Answers2

1
const char* text = doc.select_single_node("html/head/title/text()").node().value();
  • select_single_node selects the PCDATA node
  • .node() converts from xpath_node to xml_node (this is necessary since XPath nodes are either xml nodes or attributes)
  • .value() gets the value of the node (i.e. text).
zeuxcg
  • 9,216
  • 1
  • 26
  • 33
0

What I did when I was fetching PCDATA i first found the node, and after that I called

node = retrive_xml_node_from_xpath();
node.first_child().value;

So for the example you show create an xpath to find the title node, and then get its first childs value.

daramarak
  • 6,115
  • 1
  • 31
  • 50