wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes Merge two XML files using DOM Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Merge two XML files using DOM" Watch "Merge two XML files using DOM" New topic
Author

Merge two XML files using DOM

chaitu sravs
Greenhorn

Joined: Oct 21, 2009
Posts: 11
Hi,

I Have a problem in adding 2 XML files using DOM.

I have 2 XML files with content.
One file contains root element and other file does not contain root element.

I have converted first file to DOM object, and i want to append second file content to this document.
So, i have parsed second file to DOM. While parsing 2nd file, it throws an exception that "The markup in the document following the root element must be well-formed."


How can i rectify this problem?

If anybody knows, please let me know.

Thanks.
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

Please check your PM's .


SCJP, SCWCD.
|Asking Good Questions|
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

Posting your code will help others identify the problem more quickly.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
other file does not contain root element.


Well obviously, without a root element it is not an XML document and you cant parse it into a DOM.

SO - why not just treat this as a text file merging problem? How tricky is it to find the point at which the new text should be inserted?

IF you absolutely have to have the second as a DOM, add Strings for the root element opening and closing tags to the existing text.

Bill

 
Consider Paul's rocket mass heater.
 
subject: Merge two XML files using DOM
 
Similar Threads
SAX XSD Validation. Error callback is called twice.
how to remove a child (using JDOM)
Webservices with Axis 1.3
Creating Namespace XML document
Head First - Final Mock Exam, Q55