File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes [Solved] WRONG_DOCUMENT_ERR while appending child Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "[Solved] WRONG_DOCUMENT_ERR while appending child" Watch "[Solved] WRONG_DOCUMENT_ERR while appending child" New topic

[Solved] WRONG_DOCUMENT_ERR while appending child

Jeya Balaji
Ranch Hand

Joined: Jan 02, 2003
Posts: 40
Hi there,
Got some error while appending a child node.
Here is what I did.
* There exist a .xml file with few elements.
* Using Dom, I loaded the document into the memory.
* Travelled to a particular node and tried appending a newly created node.
* This doesn't work; giving the error WRONG_DOCUMENT_ERR
The skeleton is :

The last statement throws DOMException.
After reading manual, api and books, I could get only the meaning of the error code :
WRONG_DOCUMENT_ERR: Raised if newChild was created from a different document than the one that created this node.

Is there a way to tell the document to accept any node that is created at runtime?
Any help is appreciated.
[ January 22, 2003: Message edited by: Jeya Balaji ]
[ January 25, 2003: Message edited by: Jeya Balaji ]

Regards, Balaji
Jeya Balaji
Ranch Hand

Joined: Jan 02, 2003
Posts: 40
I had solved that problem with the following code :

that is, I used document instead of docImpl and document.getDocumentElement().appendChild instead of document.appendChild
I agree. Here's the link:
subject: [Solved] WRONG_DOCUMENT_ERR while appending child
It's not a secret anymore!