[xml] results from xpath



I'm using libxml for a project and I'm very impressed by the quantity of
functionnality that it offers. But I have few questions about the XPath
implementation.

xml example :

<a id="1">
 <b id="2">
  <c id="3">
   <d id="6"/>
  </c>
 </b>
 <b id="4">
  <c id="5"/>
 </b>
</a>

I would like to get the following xml portion :

<b id="2">
 <c id="3">
 </c>
</b>

So I use this XPath selection :
/a/b[ id="2"] | /a/b[ id="2"]/@* | /a/b[ id="2"]/c | /a/b[ id="2"]/c/@*

which selects the node "b" with the id=2 and its attributes.. and the
node descendant (c) of the previous b, whith all its attributes.
The Xpath selection returns 4 nodes.

 - So my first question is : Is there a way with libxml to get the
expected results in an xmlChar (or into a new small tree) ?

The same problem appears if I want to select the first node b with all
its descendant : /a/b[ id="2"]/descendant-or-self::*
It returns 3 nodes. If I use the xmlElemDump() functions, the output
print the content of all the descendant (recursion)... so the node c is
printed 2 times, and the node c is printed 3 times.

In other words, is there a way to reconstruct the origanl tree
representation only using the selected nodes and attributes ? (because
the documentation tells that the returned node array  from
xmlXPathEvalExpression() is not sorted (sorted according to what ?))
I'm a bit lost :)

Thanks.

Nicolas ANTONIAZZI.




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