Re: [xml] Dump Ancestors and Descendants of current node



Hi,

-----Original Message-----
From: xml-bounces gnome org [mailto:xml-bounces gnome org] On 
Behalf Of Michael Ransburg

Hi!

I'm doing an Expand() operation on the current node which 
means that "The node will get all its ancestors and the full 
subtree available." (according to the XMLTextReader tutorial).

By using "xmlDocDumpFormatMemoryEnc" I can now easily dump 
the current node and all its descendants to an xmlChar.

What I would like to do is to dump the current node, its 
ancestors and descendants to an xmlChar.

What's the best way to accomplish that?

Thanks,
Michael

When you write "all ancestors and the full subtree", then this could
also mean the whole doc, since the "all ancestors" includes the
document node.
Do you want to exclude any non-related children of all the ancestor
nodes instead?
Example - initial tree:
<foo>
  <goo/>
  <bar>  <-- your "current node"
    <zoo/>
  </bar>
  <boo/>
</foo>

Your result:
<foo>
  <bar>
    <zoo/>
  </bar>
</foo>

Is this what you need?
If yes, then I would select the ancestor nodes with an XPath
expression and generate a new tree; then clone the current node
into that new tree; then dump the whole new tree.
If that's too much overhead for you (XPath, new tree, cloning),
then maybe one could use the xmlTextWriter and skip the generation
of a tree and directly generate the serialized form. Since I never
used the xmlTextWriter, I'm not sure if this will work; is it 100%
possible to serialize a given node branch with the xmlTextWriter
(I'm thinking of e.g. entities here)? Does maybe an API already
exist to serialize a branch with the writer?

Cheers,

Kasimier



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