I'm trying to put this xml into a DataGridView with the data grid view only showing the nodes and the value.
I have tried using switch, case, foreach node yet the result the node and value only showing on 1 column instead 2 column. I'm tried using select single node, but it showing object error.,
Here's an example of the code:
try
{
reader = new XmlTextReader(filename);
reader.WhitespaceHandling = WhitespaceHandling.None;
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
//dataGridView1.Rows[cnt].Cells[1].Value = reader.Name;
dataGridView1.Rows.Add(reader.Name);
break;
case XmlNodeType.Text:
dataGridView1.Rows.Add("\t",reader.Value);
//dataGridView1.Rows[cnt].Cells[0].Value = reader.Value;
break;
case XmlNodeType.EndElement:
break;
}
my Mentor said, use this code but i dont know what's missing with my mentor example
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("ConfigAPI.xml");
XmlNodeList nodeList = xmlDoc.DocumentElement.SelectNodes("/ConfigAPI");
foreach (XmlNode node in nodeList)
{
node.SelectSingleNode("UIPlayer").InnerText;
}
also here's an example of the XML
<ConfigAPI>
<CoreUIAddress>http://localhost:3223</CoreUIAddress>
<CoreAppsAddress>http://localhost:3333</CoreAppsAddress>
<CoreCustomPrinterAddress>http://localhost:3001</CoreCustomPrinterAddress>
<CorePassbookPrinterAddress>http://localhost:3002</CorePassbookPrinterAddress>
<CorePrinterAddress>http://localhost:3003</CorePrinterAddress>
<CoreEDCAddress>http://localhost:3010</CoreEDCAddress>
<CoreCamAddress>http://localhost:3011</CoreCamAddress>
<CoreUPSAddress>http://localhost:3012</CoreUPSAddress>
</ConfigAPI>
by using the first code, it shown something like this (without "\t")
Column 1 Column 2
core UI Adress
http localhost
core APps
http localhost
not sure how to shown the data on 2nd Column so it can be view like this
Column 1 Column 2
Core Ui Adress Http Localhost
Core APPs Http Localhost