Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

error : "The node to be inserted is from a different document context."

Posted on 2004-11-27
5
Medium Priority
?
786 Views
Last Modified: 2008-01-09
i have 2 forms (2 different classes in same namespace in Visual Studio.net) in a C# program.
In the first form, i read XML file and push xmlnode into Stack, then pass the Stack to second form's constructor(i copied stack to second form)  
In the second form, i pop  xmlnode from the copied Stack. I create a new xmlnode. I tried to append child the new xmlnode to the xmlnode of stack, like this:  xmlnode_of_stack.appendchild(new xmlnode);

Compile is ok
But when i run at that line, i got this error "The node to be inserted is from a different document context."
I'm a new in C#.
I will accept any solution can help me out>>>

Thanks
0
Comment
Question by:therock_80
  • 2
  • 2
5 Comments
 
LVL 16

Accepted Solution

by:
muzzy2003 earned 250 total points
ID: 12686132
Try this, or whatever variant of it you need:

XmlNode newNode = xmlnode_of_stack.OwnerDocument.CreateElement("X");
xmlnode_of_stack.AppendChild(newNode);
0
 
LVL 1

Author Comment

by:therock_80
ID: 12687222
I already created new node that is parent of other new childs node along with data.
After i created this parent node, i want to append it to xmlnode_of_stack.
But you showed that you can only create new node in CreateElement method(not with parent node i created).
Also, when i tried these code;
XmlNode newNode = xmlnode_of_stack.OwnerDocument.CreateElement("X");
xmlnode_of_stack.AppendChild(newNode);
, xml document was not updated. Every nodes of xml document are pushed into stack of owner form. Then i passed this stack to its child form, so when i update the nodes in the stack, will it update xml document.

Here is passing stack i did in constructor of child form1:
private Stack form2Stack;
public form1(stack form1Stack)
{
  form2Stack = form1Stack;
}
I think it will be passsed by ref. So any time i modify nodes in form2Stack, will it automatically updated in stack of form1?


Thank yoiu
0
 
LVL 16

Expert Comment

by:muzzy2003
ID: 12687625
After adding the node, are you pushing it back onto the stack in form2, and then popping it back off in form 1?
0
 
LVL 10

Expert Comment

by:ptmcomp
ID: 12704660
Clone the node first or remove it from the original document. A node cannot be inserted in two documents at the same time. (Note: I did not read the whole thread, may be it was already mentioned before...)
0
 
LVL 1

Author Comment

by:therock_80
ID: 12712400
well i made it work.
Its so simple. I just make xmldocument is private in Form1. Then i passed it to Form2
So i guess i will give 50 points for the guy answer me
Thanks all
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question