One more word - if you do really need to create and manage doc2 as a separate document, as noted in the FAQ pointed to by the previous reply there are various ways to import doc2 into doc depending on which DOM level (and which version of Xerces) you are working with.

At 09:04 AM 11/7/2003 -0600, Mike Rawlins wrote:
Stephen,

You can't append a document to a document in the DOM, and this has nothing to do with Xerces. If you want to append what you're calling doc2 to doc, you probably want to create it as an element, though you could perhaps use as the DocumentFragment interface.

Why do you want to create one document (doc2) and append it to another (doc)?

Mike

At 01:27 AM 11/7/2003 -0800, Lingzhi Zhang wrote:

Hi,

I am experimenting how to append a piece of xml into an existing xml using
DOM. My code is like,

        DocumentBuilder parser = factory.newDocumentBuilder();
        InputSource in = new InputSource(xmlFile);
        Document doc = parser.parse(in);

I got anothe Document doc2 in the same way. The I tried

1.      doc.appendChild(doc2);
2.      doc.appendChild(doc2.getDocumentElement());
3.      doc.getDocumentElement().appendChild(doc2.getDocumentElement());
4.      aNode.appendChild(doc2);        //aNode is a node in doc

But none of the above worked, the code always throws the exception:
"org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR: A node is used in a
different document than the one that created it."

In the api it says,
"WRONG_DOCUMENT_ERR: Raised if newChild was created from a different
document than the one that created this node. "

However, I still don't understand wha this exactly means. What is wrong
with the appending in my code?

Thanks.

Stephen


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

--------------------------------------------------------------- Michael C. Rawlins, Rawlins EC Consulting www.rawlinsecconsulting.com Using XML with Legacy Business Applications (Addison-Wesley, 2003) www.awprofessional.com/titles/0321154940


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

--------------------------------------------------------------- Michael C. Rawlins, Rawlins EC Consulting www.rawlinsecconsulting.com Using XML with Legacy Business Applications (Addison-Wesley, 2003) www.awprofessional.com/titles/0321154940


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to