Connecting Tech Pros Worldwide Forums | Help | Site Map

Need advice about xpath resolving backwards

janhm
Guest
 
Posts: n/a
#1: Nov 17 '05
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




howard dierking
Guest
 
Posts: n/a
#2: Nov 17 '05

re: Need advice about xpath resolving backwards


looks like the only problem is that you're drilling too deep off of you
<kiosknavn> node. Should work if you just use the following code in your
loop...

foreach(XmlNode node in nodes){
if (node.FirstChild.Value == treeView1.SelectedNode.Text){
treeView2.Nodes.Add(node.OuterXml);
}
}

hth,

_howard

"janhm" wrote:
[color=blue]
> 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
>
>
>
>[/color]
Jan Mikkelsen
Guest
 
Posts: n/a
#3: Nov 17 '05

re: Need advice about xpath resolving backwards


Thanks.. that helped :)

It dosn't error anymore. Now it outputs <kiosknavn>kioks002</kiosknavn> so
now i have something usable to work with.

thanks


"howard dierking" <howarddierking@discussions.microsoft.com> skrev i en
meddelelse news:FCDFE0BE-E58B-47C9-8C00-7C0C3B8D856E@microsoft.com...[color=blue]
> looks like the only problem is that you're drilling too deep off of you
> <kiosknavn> node. Should work if you just use the following code in your
> loop...
>
> foreach(XmlNode node in nodes){
> if (node.FirstChild.Value == treeView1.SelectedNode.Text){
> treeView2.Nodes.Add(node.OuterXml);
> }
> }
>
> hth,
>
> _howard
>
> "janhm" wrote:
>[color=green]
>> 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
>>
>>
>>
>>[/color][/color]


Closed Thread