473,399 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Need advice about xpath resolving backwards

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

Nov 17 '05 #1
2 1509
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:
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

Nov 17 '05 #2
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" <ho************@discussions.microsoft.com> skrev i en
meddelelse news:FC**********************************@microsof t.com...
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:
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

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: MegaZone | last post by:
I'm having some issues with PHP DOMXML - in particular the get_elements_by_tagname method. Now, the PGP docs on this are, well, sparse, so maybe I'm just doing something stupid. I thought this...
2
by: kj | last post by:
Suppose I have some XML document that contains tags of the form <... xmlns:foo="http://www.bar.org/foo"> <... xmlns:foo="baz"> <... xmlns:frobozz="http://www.bar.org/foo"> What's the...
2
by: Alex | last post by:
Subject: Looking for an XML (database-based) Query Reporting Tool/advice First off, let me apologize if this thread is somewhat off topic... PLEASE REPLY TO: xml@solex-bi.com I am looking...
2
by: Kirk | last post by:
I am trying to use a simple xpath expression, the code looks like this: Dim xdoc As New System.Xml.XmlDocument Dim xnode1 As System.Xml.XmlNode Dim xlist As System.Xml.XmlNodeList ...
3
by: jsh02_nova | last post by:
When I load my xml file that has a xml schema declared for it into a xmldocument class and try to select nodes using a xpath statement, I can only select the top node which is the document. When I...
5
by: Amadej | last post by:
Hello everyone, I need some advice on which class to use when working with an XML file in a specific way. Basically I am writing a program, that needs to save it's state into a file, so it can...
2
by: probashi | last post by:
Hi, >From the sample xml, I am trying to select a book and then select the author of the select book. In the example code first SelectSingleNode selects a book. Second SelectSingleNode on the...
4
by: duduch_1er | last post by:
Hello i tried this code in my stylesheet : xsl:variable name="items" select="xsl-usexsl:getElementsBySplitString(.,'i')" /> whith the java function getElementsBySplitString here the code : ...
0
by: Joe | last post by:
Hi Could someone give me a simple explaination of this XSD which is a DataSet with relations The tables are fgFAT,e0,e1,e2,e3 which I have deleted I am trying to make sense of the part below...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.