You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by Bhat <kp...@sta.samsung.com> on 2008/01/09 06:05:33 UTC

Transferring nodes from one DOM tree to another ----- possible?

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

-- 
View this message in context: http://www.nabble.com/Transferring-nodes-from-one-DOM-tree-to-another-------possible--tp14705312p14705312.html
Sent from the Xerces - C - Users mailing list archive at Nabble.com.


Re: Transferring nodes from one DOM tree to another ----- possible?

Posted by Alberto Massari <am...@datadirect.com>.
Check if the destructor for this object is being called after 
XMLPlatformUtils::Terminate has already been called.

Alberto

Bhat wrote:
> Alberto Massari wrote:
>   
>>  
>> (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
>>
>>
>>     
>
> Alberto: You hit the nail on the head.  Deleting the XMLFormatTarget object
> did the trick.  Thanks a bunch....
>
>
> I have written a class in which I am, among other things, parsing an XML
> document.  In the constructor I am instantiating the XercesDOMParser. 
> Naturally, in the destructor I deleted this object, but that is causing a
> core-dump.  Any suggestions?
>
> Thanks,
> Bhat
>
>
> am instantiating the parser, the  
>
>
>   



Re: Transferring nodes from one DOM tree to another ----- possible?

Posted by Bhat <kp...@sta.samsung.com>.

Alberto Massari wrote:
> 
>  
> (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
> 
> 

Alberto: You hit the nail on the head.  Deleting the XMLFormatTarget object
did the trick.  Thanks a bunch....


I have written a class in which I am, among other things, parsing an XML
document.  In the constructor I am instantiating the XercesDOMParser. 
Naturally, in the destructor I deleted this object, but that is causing a
core-dump.  Any suggestions?

Thanks,
Bhat


am instantiating the parser, the  


-- 
View this message in context: http://www.nabble.com/Transferring-nodes-from-one-DOM-tree-to-another-------possible--tp14705312p14744085.html
Sent from the Xerces - C - Users mailing list archive at Nabble.com.


Re: Transferring nodes from one DOM tree to another ----- possible?

Posted by Alberto Massari <am...@datadirect.com>.
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
>
>