Re: [xml] results from xpath




-----BEGIN PGP SIGNED MESSAGE-----
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 
more
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 :
|b|id|c|id|

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:apply-templates/>
</xsl:template>

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

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

~Chris
- -- 
Christopher R. Maden, Principal Consultant, crism consulting
XML-SGML-HTML-DTDs-schemas-XSL-DSSSL-conversion-training-ebooks-B2B
<URL: http://crism.maden.org/consulting/ >
PGP Fingerprint: BBA6 4085 DED0 E176 D6D4  5DFC AC52 F825 AFEC 58DA
-----BEGIN PGP SIGNATURE-----
Version: PGP Personal Privacy 6.5.8

iQA/AwUBQJ9b4qxS+CWv7FjaEQIMEgCgvXMoVJE0T3Q3AObBMt8YbDC8DU4AoIsO
jnGvevsMrhFEWvQ/J7E9CtaL
=NXan
-----END PGP SIGNATURE-----




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