Re: [xml] results from xpath

Hash: SHA1

At 03:39 10/5/04, Nicolas ANTONIAZZI wrote:
if you have the appropriate DTD or schema information available.  But now,
you don't *copy* those nodes - you retrieve information from them and
output it.  xmlElemDump(), as you've discovered, will give you the entire
element - not just its start- and end-tags.  Instead, write new elements
that share information from the old ones.  (Sorry for no example - I'm 
familiar with the Perl XML::LibXML interface than the direct C API.)

I'm not sure to understand your last point.
Using my previous example, if I get an array with some nodes results :

result array :

I assume you mean: the element with name "b", the id attribute of that 
element, the element with name "c", and the id attribute of that element.

Unless there are attributes that you want to leave out of your result tree, 
I would probably just target the elements themselves, and then copy all of 
their attributes.

Do you suggest me to traverse this array and create a new tree (of new
nodes) and looking for these elements to know which one is the parent
(or the child) of another one ?

That would be one way to do it, if you don't have any advance knowledge of 
the relationship between your target elements.  So in pseudocode:

while there are nodes in the list {
   is any other node in list an ancestor of the first node?
     if so, skip this node for now.
   create an output element with the same name as this node and copy the 
attributes over
   remove the node from the list
   start again at the start of the list

This is very easy to do in XSLT:

<xsl:template match="*">

<xsl:template match="text()"/>

<xsl:template match="b[ id='2'] | c[ id='3']">
     <xsl:copy-of select="@*"/>

- -- 
Christopher R. Maden, Principal Consultant, crism consulting
<URL: >
PGP Fingerprint: BBA6 4085 DED0 E176 D6D4  5DFC AC52 F825 AFEC 58DA
Version: PGP Personal Privacy 6.5.8


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