lb said:Anyone know if there's a fast way to copy childNodes from one XML document to another using Oracle XML?
What about Apache XML?
Martin Honnen said:If you use the W3C DOM Document object then you can use the method importNode to import nodes from another document and you can then append them to your document:
The problem is that I have about 20000 "section" nodes to be moved. I'm looking for something like sections1.appendChildNodes(section2.getChildNodes). Do I really have to import and append 20000 times?
Jörn W. Janneck said:LB wrote:
[snip]The problem is that I have about 20000 "section" nodes to be moved. I'm looking for something like sections1.appendChildNodes(section2.getChildNodes). Do I really have to import and append 20000 times?
lars:
have you considered the use of xslt for the task?
LB said:Thanks, but I meant moving/copying a NodeList from one document to another:
Doc 1:
<root>
<sections>
<section source="doc1"/>
<section source="doc1"/>
</sections
</root>
Doc 2:
<root>
<sections>
<section source="doc2"/>
<section source="doc2"/>
</sections
</root>
I want this result:
Doc 1:
<root>
<sections>
<section source="doc1"/>
<section source="doc1"/>
<section source="doc2"/>
<section source="doc2"/>
</sections
</root>
The problem is that I have about 20000 "section" nodes to be moved. I'm looking for something like sections1.appendChildNodes(section2.getChildNodes). Do I really have to import and append 20000 times?
Martin Honnen said:You could first copy the nodes into a DocumentFragment and then insert/append that. However with 20000 nodes I wonder whether DOM is a good solution at all, you might be better off with some SAX processing
Thanks for the suggestions. I have to think of an alternative since Oracle's parses doesn't seem to be able to handle large numbers of nodes.
Example (see end) where results2 holds about 3600 childNodes:
Node newResults1 = doc.importNode(results2, true);
results1.getParentNode.appendChild(newResults1);
Node newResults2 = doc.importNode(results2, true);
results1.getParentNode.appendChild(newResults2);
Node newResults3 = doc.importNode(results2, true);
results1.getParentNode.appendChild(newResults3);
I'm calling this in a struts action of a web application and during the third importNode call, some kind of error occurs. When debugging there's no exception.The instruction pointer just vanishes into thin air.
However, if I create a XML file containing the above and then load it, there 's no error. Although there could be other reasons, this little experiment indicates that something is not working properly in the Oracle XML parser.
Lars
In the experiment above I'm just appending results as siblings so the end result should be:
<root>
<results>
<sections>
<section source="doc1"/>
<section source="doc1"/>
</sections>
</results>
<results>
<sections>
<section source="doc2"/>
<section source="doc2"/>
</sections>
</results>
<results>
<sections>
<section source="doc2"/>
<section source="doc2"/>
</sections>
</results>
<results>
<sections>
<section source="doc2"/>
<section source="doc2"/>
</sections>
</results>
</root>
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.