Re: [xml] How to use XPath to retrieve the "leaf" item?

On 9/12/2012 11:58, Ramon F Herrera wrote:
which is easy enough to parse. Next, I made a discovery: If I add an extra function at the end of the string, I obtain exactly what I need:
XPath query: /table/properties/length/text()
Result: 62.42

That function works properly with all XPath implementations that I have tried, EXCEPT with libxml.
Result (1 nodes):
= node "text": type 3
I need the last step, after the node set. How do I retrieve that end item?

You're on the right path, you just need xmlNodeGetContent on that node.

It would be best to xpath for "/table/properties/length" and use xmlNodeGetContent on the element, though, in case there's more than one text node or the text isn't directly in a text node child of length, such as:
<length units="ft">62<![CDATA[.42]]></length>

"/table/properties/length/text()" would give you "62", but "/table/properties/length" gives 62.42


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]