这是英文的帖子:Hi,I've got the following piece of code that's causing me a bit of a problemXmlDocument 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.网友的回复: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 ImportNoderootNode.AppendChild(doc.ImportNode(rolesNode,true));instead of the previous AppendChild.best regards
ricardo