Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Merge two XML files using DOM

 
chaitu sravs
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please check your PM's .
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Posting your code will help others identify the problem more quickly.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic