Hello,
I am trying to read from a XML file in C#. I have coded a waypoints system. I can save the waypoints in an XML file. My problem is I have little free time to work on it. I ran into a problem trying to read from my XML. Any help like examples to helpful links will suffice.
XML File
Code:
<?xml version="1.0"?>
<Path>
<Name>SW Test</Name>
<Nodes>
<Node id="0" x="-8832.103" y="637.4868" z="0" />
<Node id="1" x="-8832.148" y="637.5655" z="0" />
<Node id="2" x="-8827.26" y="637.9915" z="0" />
<Node id="3" x="-8822.965" y="637.6017" z="0" />
<Node id="4" x="-8818.634" y="640.0749" z="0" />
<Node id="5" x="-8814.84" y="639.9224" z="0" />
<Node id="6" x="-8811.952" y="636.7586" z="0" />
<Node id="7" x="-8811.789" y="631.8894" z="0" />
<Node id="8" x="-8812.003" y="631.8409" z="0" />
<Node id="9" x="-8818.141" y="628.4603" z="0" />
<Node id="10" x="-8820.524" y="627.1432" z="0" />
</Nodes>
<Sellers>
<Seller id="0" />
</Sellers>
</Path>
This is the code I have come up with, it does not work.
Code:
//* create an xml document object.
XmlDocument xmlDoc = new XmlDocument();
//* load the XML document from the specified file,
xmlDoc.Load(@"C:\\xml2.xml");
//* Get elements.
XmlNodeList node = xmlDoc.GetElementsByTagName("Nodes");
XmlNodeList seller = xmlDoc.GetElementsByTagName("Sellers");
//* Display the results.
for (int i = 0; i < 1000; i++)
{
OutPut("Node ID: " + node[i].InnerText);
}
OutPut("Seller ID: " + seller[0].InnerText);
I know it has something to do with the fact that node has 3 vars and I am only reading one. I just can figure it out.
Thanks for your help and time. +Rep to all that help!