Thanks for the reply.
Apparently you cannot simply create an XmlNode outside of an XmlDocument..
So, here is what I ended up doing.
Inside of my main config class, I have this property:
public XmlNode FormSettings
{
get
{
return XmlDoc.DocumentElement.SelectSingleNode("/configuration/" + cfgSettings.formSettings);
}
set
{
XmlNode Root = XmlDoc.DocumentElement.SelectSingleNode("/configuration/" + cfgSettings.formSettings);
if (Root == null)
{
Root = XmlDoc.DocumentElement.SelectSingleNode("/configuration");
XmlNode newNode = XmlDoc.CreateNode(XmlNodeType.Element, cfgSettings.formSettings, "");
Root = Root.AppendChild(newNode);
}
else
Root.RemoveAll();
for (int node = 0 ; node < value.ChildNodes.Count ; node++)
{
XmlElement Element = XmlDoc.CreateElement(value.ChildNodes[node].Name);
for (int attrib = 0 ; attrib < value.ChildNodes[node].Attributes.Count ; attrib++)
Element.SetAttribute(value.ChildNodes[node].Attributes[attrib].LocalName, value.ChildNodes[node].Attributes[attrib].Value);
Root.AppendChild(Element);
}
}
}
I can easily parse that node wherever I want, without needing a reference to xmlDoc.
This allows me to put all of the code to build/parse/manage a particular forms config inside of that form class itself, instead of having to put it in the main applicaitons config file class.
To build a node I use the following code:
public XmlNode ConvertToXmlNode()
{
XmlDocument xmlDoc = new XmlDocument();
System.Xml.XmlNode Node = xmlDoc.CreateNode(XmlNodeType.Element, "Config", "");
System.Xml.XmlElement Element = null;
Element = xmlDoc.CreateElement("Image"); Element.SetAttribute("value", Image); Node.AppendChild(Element);
Element = xmlDoc.CreateElement("Background_Color"); Element.SetAttribute("value", Background_Color.ToArgb().ToString()); Node.AppendChild(Element);
Element = xmlDoc.CreateElement("AntiAlias"); Element.SetAttribute("value", AntiAlias.ToString()); Node.AppendChild(Element);
return Node;
}
This works very well and makes managing code and configs for many diferent forms much easier than the previous method where I defined all of the configurable params inside of the parent xml/cfg class itself.
Now I can easily insert/remove forms/modules to my app without having to hack up a config class as well with a ton of properties.
I hope this helps someone searching in the future...