473,385 Members | 1,564 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Getting exception "The node to be inserted is from a different document context."

Hi,

I've got the following piece of code that's causing me a bit of a problem

XmlDocument doc = new XmlDocument ();
XmlNode rootNode = doc.CreateNode (XmlNodeType.Element, "usersettings",
null);
User user = new User (userid);
XmlNode rolesNode = user.GetRoles ();
rootNode.AppendChild (rolesNode);
:
:

The last line (rootNode.AppendChild (rolesNode)) throws an exception "The
node to be inserted is from a different document context." How can I work
around this? The code above is from a Web-service that collects various
information regarding a user from different sources each of which returns an
XmlNode. The web-service adds each XmlNode to a "root" node and then returns
this "root" node to the client.

Eirik M.
Nov 11 '05 #1
2 55446
The proble you're having relates to the fact that the user object is
creating a node from othe document, rather than from doc.

Either you pass doc to GetRoles so that the nodes are created from the
correct instance, or you may have to use ImportNode

rootNode.AppendChild(doc.ImportNode(rolesNode,true ));

instead of the previous AppendChild.

best regards
ricardo

"Eirik M." <eirik_at_stockpoint_dot_no> wrote in message
news:eC**************@tk2msftngp13.phx.gbl...
Hi,

I've got the following piece of code that's causing me a bit of a problem

XmlDocument doc = new XmlDocument ();
XmlNode rootNode = doc.CreateNode (XmlNodeType.Element, "usersettings",
null);
User user = new User (userid);
XmlNode rolesNode = user.GetRoles ();
rootNode.AppendChild (rolesNode);
:
:

The last line (rootNode.AppendChild (rolesNode)) throws an exception "The
node to be inserted is from a different document context." How can I work
around this? The code above is from a Web-service that collects various
information regarding a user from different sources each of which returns an XmlNode. The web-service adds each XmlNode to a "root" node and then returns this "root" node to the client.

Eirik M.

Nov 11 '05 #2
Hi, Ricardo

Thanks for your quick reply.

"news.microsoft.com" <ricardo pereira> wrote in message
news:ur**************@TK2MSFTNGP11.phx.gbl...
The proble you're having relates to the fact that the user object is
creating a node from othe document, rather than from doc.

Either you pass doc to GetRoles
Nah, don't wan't to pass it around.
so that the nodes are created from the
correct instance, or you may have to use ImportNode

rootNode.AppendChild(doc.ImportNode(rolesNode,true ));
Did the trick!

instead of the previous AppendChild.

best regards
ricardo
Eirik M ^_^

"Eirik M." <eirik_at_stockpoint_dot_no> wrote in message
news:eC**************@tk2msftngp13.phx.gbl...
Hi,

I've got the following piece of code that's causing me a bit of a problem
XmlDocument doc = new XmlDocument ();
XmlNode rootNode = doc.CreateNode (XmlNodeType.Element, "usersettings",
null);
User user = new User (userid);
XmlNode rolesNode = user.GetRoles ();
rootNode.AppendChild (rolesNode);
:
:

The last line (rootNode.AppendChild (rolesNode)) throws an exception "The node to be inserted is from a different document context." How can I work around this? The code above is from a Web-service that collects various
information regarding a user from different sources each of which
returns an
XmlNode. The web-service adds each XmlNode to a "root" node and then

returns
this "root" node to the client.

Eirik M.


Nov 11 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Kali K E | last post by:
Hi, I could not understand how I can do the following things in Python. Please help me. 1. First I have to find the current directory from where the script is invoked. 2. Next I have to form a...
4
by: Pavils Jurjans | last post by:
Hello, I am interested in getting the XML contents as text between two XML elements that I know follow each other. They could be in completely different levels, but in XML file the first is...
5
by: Horst Walter | last post by:
What is wrong here? IPAddress ipAddress = IPAddress.Parse("10.10.20.1"); IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, this.port); this.tcpClient = new TcpClient(ipEndPoint); // PROBLEM HERE...
5
by: Paw Pedersen | last post by:
When you are "working" on a specific node from a XmlDocument instance, is it possible to get the full xpath to this node? Regards Paw
9
by: | last post by:
Is there any sample about getting the results from executing an exe using C#? Thanks for answering.
10
by: Paul H | last post by:
I am trying to get the spec for a database. The trouble is the client frequently blurts out industry jargon, speaks insanely quickly and is easily sidetracked. They are currently using around 30...
3
by: scripter199 | last post by:
Hi, Im adding textboxes dynamically from an onclick event that calls the function below: function addRowDynamic() { rowCnt++; lookupCnt++; id++; //add a row to the rows...
1
by: tamasumalta | last post by:
I am using the attached code Private Sub StartApplicationProcess InitialiseObject() oWord.Visible = True oDoc = oWord.Documents.Open(StrStackPath) oWord.Visible = True end sub The...
4
by: yogarajan | last post by:
The specified module could not be found. (Exception from HRESULT: 0x8007007E) Description: An unhandled exception occurred during the execution of the current web request. Please review the stack...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.