Hi all,
I've got a settings.xml file in which are some default settings I want to display on a form in a application.
The settings.xml is built up like this:
<router>
<name>Test</name>
<ip>192.168.100.3</ip>
<description>Hello</description>
<ttl>255</ttl>
<threshold>100</threshold>
<suspended>no</suspended>
</router>
I want to place the data within the XMl into a few variables....this is the code I have so far.
try
{
XmlDocument xd = new XmlDocument();
XmlTextReader xmlreader = new XmlTextReader("C:\\settings.xml"
string test = xmlreader.ReadString();
if (test != null)
{
xd.InnerXml = test;
XmlNode RouterNode = xd.ChildNodes[0];
XmlNode NameNode;
XmlNode IPNode;
XmlNode DescriptionNode;
XmlNode TTLNode;
XmlNode ThresholdNode;
XmlNode SuspendedNode;
NameNode = RouterNode.ChildNodes[0];
// test
MessageBox.Show(NameNode.OuterXml);
IPNode = RouterNode.ChildNodes[1];
DescriptionNode = RouterNode.ChildNodes[2];
TTLNode = RouterNode.ChildNodes[3];
ThresholdNode = RouterNode.ChildNodes[4];
SuspendedNode = RouterNode.ChildNodes[5];
string routername = NameNode.InnerXml.ToString();
MessageBox.Show(routername);
// etc the rest of the nodes
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
When I run I get the exception: root element missing
Does someone have some tips or advice?
Thanks!
- Raenius
"Free will...is an illusion"
I've got a settings.xml file in which are some default settings I want to display on a form in a application.
The settings.xml is built up like this:
<router>
<name>Test</name>
<ip>192.168.100.3</ip>
<description>Hello</description>
<ttl>255</ttl>
<threshold>100</threshold>
<suspended>no</suspended>
</router>
I want to place the data within the XMl into a few variables....this is the code I have so far.
try
{
XmlDocument xd = new XmlDocument();
XmlTextReader xmlreader = new XmlTextReader("C:\\settings.xml"
string test = xmlreader.ReadString();
if (test != null)
{
xd.InnerXml = test;
XmlNode RouterNode = xd.ChildNodes[0];
XmlNode NameNode;
XmlNode IPNode;
XmlNode DescriptionNode;
XmlNode TTLNode;
XmlNode ThresholdNode;
XmlNode SuspendedNode;
NameNode = RouterNode.ChildNodes[0];
// test
MessageBox.Show(NameNode.OuterXml);
IPNode = RouterNode.ChildNodes[1];
DescriptionNode = RouterNode.ChildNodes[2];
TTLNode = RouterNode.ChildNodes[3];
ThresholdNode = RouterNode.ChildNodes[4];
SuspendedNode = RouterNode.ChildNodes[5];
string routername = NameNode.InnerXml.ToString();
MessageBox.Show(routername);
// etc the rest of the nodes
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
When I run I get the exception: root element missing
Does someone have some tips or advice?
Thanks!
- Raenius
"Free will...is an illusion"