keegan3d
keegan3d

Reputation: 11305

libxml2: xpath from xmlNode

I've looked through the docs and it seems that you can only execute an xpath search from a xmlDocPtr by creating an xpath context. Is there anyway in libxml2 to xpath search from a xmlNodePtr?

Upvotes: 0

Views: 3461

Answers (2)

Remy Lebeau
Remy Lebeau

Reputation: 597081

Call xmlXPathNewContext(), specifying the real top-level xmlDocPtr for the document, then set the xmlXPathContext::node field to the desired xmlNodePtr pointer that is a child of the xmlDocPtr document.

Upvotes: 1

keegan3d
keegan3d

Reputation: 11305

It turns out you can cast xmlNodePtr to xmlDocPtr and visa-versa.

Upvotes: 0

Related Questions