Ben Nadel
On User Experience (UX) Design, JavaScript, ColdFusion, Node.js, Life, and Love.
I am the chief technical officer at InVision App, Inc - a prototyping and collaboration platform for designers, built by designers. I also rock out in JavaScript and ColdFusion 24x7.
Meanwhile on Twitter
Loading latest tweet...
Ben Nadel at cf.Objective() 2014 (Bloomington, MN) with:

WRONG_DOCUMENT_ERR: A Node Is Used In A Different Document Than The One That Created It

By Ben Nadel on
Tags: ColdFusion

Earlier today, I posted about transferring XML nodes from one ColdFusion XML document object to another. I briefly mentioned that if you try to do that without first importing the target nodes, ColdFusion will throw the following error:

WRONG_DOCUMENT_ERR: A node is used in a different document than the one that created it

It turns out though, this is the same error you would get for trying to add the same node to multiple parents of the same document (something I did accidentally in my code). This error, which made sense for the different documentation use, makes very little sense here (using this wording). Anyway, just thought I would post this finding in case anyone comes across it and is like "But I am only using ONE document?!?!?!?"

Reader Comments

Hey man,

I was getting the exact same error too. But in a very different context.

I used Axis to generate Java proxy class for a web service- all in eclipse.

But when I call one of the service methods through the proxy, i get this error (via Axis).

Can you help?


Reply to this Comment


Hmm, you've got me! I've never actually touched the Axis files directly -- I've only ever gone through ColdFusion and had them do it behind the scenes (ie. using the ?wsdl style invocation).

I wouldn't even know where to begin debugging something like this. Sorry :(

Reply to this Comment


Oh okay, thanks neway mate :)
Spent some hours but did figure it out eventually.
It was due to a mal-formed SOAP reply from the sever, and that too a govt server :P


Reply to this Comment

Hi, I have the same problem, I noticed that a fault SOAP response with a detail node is causing the problem. Could you confirm if you are in the same situation, it could give us a clue to find the solution.

Reply to this Comment


I'm trying to diagnose a problem I'm having where my site throws this WRONG_DOCUMENT_ERR exception. I tried to reproduce the error you experienced by adding the same node to multiple parents of the same document.

I could not reproduce this error using the code below. Do you think a bug has been fixed or am I doing something wrong in trying to reproduce the error?

  • try {
  • xDoc = XMLNew();
  • xDoc.xmlRoot = XmlElemNew(xDoc,"MyRoot");
  • for (i = 1; i LTE 2; i++) {
  • xDoc.MyRoot.XmlChildren[i] = XmlElemNew(xDoc,"parent#i#");
  • xDoc.MyRoot.XmlChildren[i].XmlText = "This is parent node " & i &".";
  • for (j = 1; j LTE 3; j++) {
  • xDoc.MyRoot.XmlChildren[i].XmlChildren[j] = XmlElemNew(xDoc,"child#j#");
  • xDoc.MyRoot.XmlChildren[i].XmlChildren[j].XmlText = "This is child node " & j &" of parent " & i & ".";
  • }
  • }
  • newNode = xmlelemnew(xDoc,"newNode");
  • ArrayAppend(xDoc.MyRoot.parent1.XmlChildren,newNode);
  • ArrayAppend(xDoc.MyRoot.parent2.XmlChildren,newNode);
  • }
  • catch (exception e) {
  • writeoutput("There was an error.<br />");
  • }
  • writedump(var=xDoc);

Reply to this Comment

Post A Comment

You — Get Out Of My Dreams, Get Into My Comments
Live in the Now
Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.