Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 12th, 2003, 03:10 PM
Authorized User
 
Join Date: Nov 2003
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Concatenating many XML files

Hi ...

My program accesses 50 xml files one at a time, uses JAXP API and DOM parser to update each and puts the updated DOM into a new XML file. So, I will be left with 50 updated xml files. Its fine till now...

But what I want to accomplish is to have a SINGLE xml file as output instead of 50 different xml files.

i tried to append one dom to an other as a child element but it didnt work as we cannot append DOMs.

Is there any way to concatenate these XML files? Infact, I need to concatenate the first child of every XML file in to a single new xml file.
Any suggestion is greatly appreciated!

Thanks.
-Srivalli.

 
Old November 13th, 2003, 03:59 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 147
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to armmarti
Default

DOM 2 introdiced importNode method. Try to use it if your DOM implementation supports it. If not, you can write a recursive method which will make deep-copy of a DOM node and hence you'll be able to: a) create new document object, b) create copies of all root-nodes of those 50 documents and then c) append them as children to the newly created document.

Regards,
Armen
 
Old November 13th, 2003, 11:31 AM
Authorized User
 
Join Date: Nov 2003
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi armmarti....
Thanks for your reply.
I tried to implement hte recursive approach but failed.

Here is my code fragment...
-----------------------------
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            doc = db.newDocument();
            r=doc.createElement("nmstat");
            Element n=(Element)currDocument.getDocumentElement().getFi rstChild();
            r.appendChild(n);
----------------------------------

It throws the following error...
-------------------------------------
Exception in thread "main" org.apache.crimson.tree.DomEx: WRONG_DOCUMENT_ERR: Th
at node doesn't belong in this document.
        at org.apache.crimson.tree.ParentNode.checkDocument(P arentNode.java:250)

        at org.apache.crimson.tree.ParentNode.appendChild(Par entNode.java:333)
        at anno.writeToDOS(anno.java:323)
---------------------------------------

Could you help me in fixing the error?
Can u provide me with a sample code, if possible.

Any help is greatly appreciated!


 
Old November 13th, 2003, 01:30 PM
Authorized User
 
Join Date: Nov 2003
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi all...
I could get my code working perfectly.

here it goes...
if (document==null)
document=currDocument;
else{
Element ele = (Element)currDocument.getDocumentElement().getFirs tChild();
if (ele!=null){
Node replacingNode = ((document).importNode(ele, true));
document.getDocumentElement().appendChild(replacin gNode);
}
}
---------------------
Thanks a lot for all your help.If it werent for ur help, I wouldn't have solved it!

 
Old March 30th, 2006, 03:05 AM
Registered User
 
Join Date: Mar 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey I am facing same prob can you please send me that whole code which is transforming many xml to one xml please..






Similar Threads
Thread Thread Starter Forum Replies Last Post
concatenating records rashi Access VBA 9 November 6th, 2008 05:07 PM
Problem to create an xml file from two xml files saurabh_inblore XSLT 1 April 12th, 2006 02:58 AM
Concatenating files modification jkmyoung J2EE 0 November 23rd, 2004 03:17 PM
Concatenating many XML files srivalli9 J2EE 0 November 12th, 2003 03:14 PM
Merge XML files into a xml file using xslt lxu XML 4 November 6th, 2003 06:01 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.