Re: [xml] XPath oddities



On Fri, Nov 02, 2001 at 10:42:27AM +0000, Jon Topper, Active High Ltd. wrote:
What I'm trying to do is reference the node matching
"/html/head/script/CC-SCRIPT" within that document so that I can exchange
it for a new text node - almost a search-and-replace operation, if you
like.

I've used xmlXPathEval() to evaluate the path expression and then
xmlXPtrBuildNodeList() to build a node list of the results.  This node
list doesn't appear to bear any relevance to the matched node in the
original document though - I can't simply use it with xmlReplaceNode(), or
whatever to make the change.

what we do is a sequence of 

* xmlXPathCompileEval() 

to compile the path
then we use the result with 

* xmlXPathCompiledEval() 

to get the nodes in a nodeset
xmlXPathCompiledEval returns a structure so you get the node set like this:

* my_nodeset = result->nodesetval;

in the nodeset you can select each node and modify it as you like
(pay attention modifing the nodeset itself will have no effect)

Have I got the wrong end of the stick somewhere?  Is what I'm attempting
to do actually possible?

you can even do it with relative xpaths :)

there is a simplified interface to libxml2 XPath selection in the 
perl module XML::LibXML you can get from cpan.perl.com
check the xpath.c file for details.

christian




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