Hi Bhat,
if your purpose is to have a DOM tree containing the desired (filtered) DOM nodes, you should create a new DOMDocument, add it a root node, use importNode to migrate the nodes from the original document to the new one, and appendChild to place it under the root node. If instead you need a valid XML file, I would create the XMLFormatTarget, write the <root> string in it, run the recursive function that fills in the data, write </root>, and close the object (the fact that you don't see the size of the file until you exit your application is probably caused by not having closed/destroyed the XMLFormatTarget).

Alberto

Bhat wrote:
I am still looking for a solution to create a new DOM tree from an existing
DOM tree by piecing together all the subtrees that are rooted at the nodes
with the specified name.  This shouldn’t be that hard!  Ideally I would like
my function to accept teo inputs ---- the original DOM and the node name
---- and it returns the new DOM.  It would be better if these nodes are
snipped from the original DOM tree.  Can somebody help?


As a less preferred approach, I can live with a function that creates a new
XML file.  As you already know, I have already created a function that
plucks the desired XML content from the original file and dumps it into
another file.  The problem is, of course, that the resultant file is
ill-formed since it is missing not only the XML declaration statement but
the root node as well.

Based on David Bertoni's suggestion, I decided to add the missing markups
and create a proper XML file.  Here’s the pseudo code I used:
1). Open a new XML file and the ill-formed XML file (which is created by my
function, as mentioned above)
2). Write the XML declaration statement to the new XML file
3). Write the root tag (opening) to the new XML file
4). Find the size of the ill-formed XML file 5). Break the contents of the ill-formed XML file into fixed sized blocks,
plus "change"
6). Read the contents of the ill-formed XML file to the new XML file
7). Write the root tag (closing) to the new XML file
8). Close the new XML file and the ill-formed XML file


The problem is that I am getting the error at step 4.  For some reason, as
long as the application is running, I keep getting the size of the
ill-formed XML file as zero.  The result is that the new XML file only
contains the XML declaration statement and the root opening and closing
tags.  I verified this by halting the application (both with a cin statement
and in the debugger) and doing an ls -l on the file.  I moved my pseudo code
to the very end of the application.  I even invoked my pseudo code from
atexi, but to no avail.  Only after the application exits does the content
appear in the ill-formed XML file.

Any suggestions?  I am all ears.

Bhat



Reply via email to