Skip to main content
Ben Nadel at CFUNITED 2009 (Lansdowne, VA) with: Dee Sadler
Ben Nadel at CFUNITED 2009 (Lansdowne, VA) with: Dee Sadler

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

By
Published in Comments (9)

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

2 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?

Raener

15,902 Comments

@Raener,

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 :(

2 Comments

@Ben

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

Raener

2 Comments

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.

1 Comments

@Ben

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);
I believe in love. I believe in compassion. I believe in human rights. I believe that we can afford to give more of these gifts to the world around us because it costs us nothing to be decent and kind and understanding. And, I want you to know that when you land on this site, you are accepted for who you are, no matter how you identify, what truths you live, or whatever kind of goofy shit makes you feel alive! Rock on with your bad self!
Ben Nadel