M
Mungo Jerrie
Hi there 
I have some problems with the same instance of my xmldocument across 3
different classes. See code below:
class one {
protected static XmlDocument doc = new XmlDocument();
public static XmlDocument getXmlDocument(){
XmlDocument doc = new XmlDocument();
XmlDeclaration xmlDecl = doc.CreateXmlDeclaration("1.0",
"iso-8859-1", null); //"iso-8859-1"
doc.InsertBefore(xmlDecl, doc.DocumentElement);
return doc;
}
}
class two{
private static XmlDocument doc = one.getXmlDocument();
public static XmlElement getNewXmlElement(string elementName, string
stringValue)
{
XmlElement element = doc.getXmlDocument().CreateElement("",
elementName, null);
element.InnerText = stringValue;
return element;
}
}
class test{
XmlDocument doc = one.getXmlDocument();
XmlElement e = two.getNewXmlElement("ReferencedOrder", "test");
doc.AppendChild(e);
doc.Save(Console.Out);
}
Error:
An unhandled exception of type 'System.ArgumentException' occurred in
system.xml.dll
Additional information: (translated from danish) The node to be inserted
comes from a different documentcontext
Does anyone know why ?

I have some problems with the same instance of my xmldocument across 3
different classes. See code below:
class one {
protected static XmlDocument doc = new XmlDocument();
public static XmlDocument getXmlDocument(){
XmlDocument doc = new XmlDocument();
XmlDeclaration xmlDecl = doc.CreateXmlDeclaration("1.0",
"iso-8859-1", null); //"iso-8859-1"
doc.InsertBefore(xmlDecl, doc.DocumentElement);
return doc;
}
}
class two{
private static XmlDocument doc = one.getXmlDocument();
public static XmlElement getNewXmlElement(string elementName, string
stringValue)
{
XmlElement element = doc.getXmlDocument().CreateElement("",
elementName, null);
element.InnerText = stringValue;
return element;
}
}
class test{
XmlDocument doc = one.getXmlDocument();
XmlElement e = two.getNewXmlElement("ReferencedOrder", "test");
doc.AppendChild(e);
doc.Save(Console.Out);
}
Error:
An unhandled exception of type 'System.ArgumentException' occurred in
system.xml.dll
Additional information: (translated from danish) The node to be inserted
comes from a different documentcontext
Does anyone know why ?