[xml] help: how to get content of an element via XPath in libxml2



help: how to get content of an element via XPath in libxml2


Stupid question, but...

I am using libxml2, 2.5.6

I want to be able to use XPath syntax to get the textual content
of a field of a record.  E.g. for something like:

<record>
   <field>value</field>
   <field1> value1 
     <baz/> 
   </field>
</record>

after having parsed the above, I want to be able to do something like

assert(
   document.get_by_xpath("/record/field")
   == "value"
)

and

assert(
   document.get_by_xpath("/record/field1")
   == " value\n     <baz\>\n   "
)


ok, I wrote the above in a C++ style syntax
- in C it might look like


assert(
   0 == strcmp( xmlGetContent(xmlXPathEvalExpression(document,"/record/field")))
                "value" )
)

(with a memory leak... yeah, yeah...)


I must be stupid, or, at least, lacking a good browser,
but I can't figure out how to go from xmlXPathEvalExpression
to any of the xmlNodeGetContent or similar functions.




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