J
janhm
Hey, I had a problem with adding xml into a treeview few month ago. The
project got abandon, but im now working with it again.
Here is my problem:
I have an xml file containing:
<?xml version="1.0"?>
<kiosks>
<kiosk>
<kiosknavn>KIOSK001</kiosknavn>
<serienummer>001001001001</serienummer>
</kiosk>
<kiosk>
<kiosknavn>KIOSK002</kiosknavn>
<serienummer>002002002002</serienummer>
</kiosk>
and so on.
I then fill a treeview with all the <kiosknavn> in the xml. No problems
there...
Now I want to be able to search in the <kiosknavn> and have the content
displayed in another treeview.
If I search/click in treeview1 for KIOSK002 then I want the "KIOSK002" and
"002002002002" to be added into this second treeview.
I tried this :
treeView2.Nodes.Clear();
XmlDocument xDoc = new XmlDocument();
xDoc.Load("c://test.xml");
XmlNodeList nodes = xDoc.GetElementsByTagName("kiosknavn");
foreach(XmlNode node in nodes)
{
if (node.FirstChild.FirstChild.Value == treeView1.SelectedNode.Text)
{
treeView2.Nodes.Add(node.OuterXml);
}
}
But it only results in :
Object reference not set to an instance of an object.
Any advice?
Thanks
project got abandon, but im now working with it again.
Here is my problem:
I have an xml file containing:
<?xml version="1.0"?>
<kiosks>
<kiosk>
<kiosknavn>KIOSK001</kiosknavn>
<serienummer>001001001001</serienummer>
</kiosk>
<kiosk>
<kiosknavn>KIOSK002</kiosknavn>
<serienummer>002002002002</serienummer>
</kiosk>
and so on.
I then fill a treeview with all the <kiosknavn> in the xml. No problems
there...
Now I want to be able to search in the <kiosknavn> and have the content
displayed in another treeview.
If I search/click in treeview1 for KIOSK002 then I want the "KIOSK002" and
"002002002002" to be added into this second treeview.
I tried this :
treeView2.Nodes.Clear();
XmlDocument xDoc = new XmlDocument();
xDoc.Load("c://test.xml");
XmlNodeList nodes = xDoc.GetElementsByTagName("kiosknavn");
foreach(XmlNode node in nodes)
{
if (node.FirstChild.FirstChild.Value == treeView1.SelectedNode.Text)
{
treeView2.Nodes.Add(node.OuterXml);
}
}
But it only results in :
Object reference not set to an instance of an object.
Any advice?
Thanks