473,545 Members | 1,310 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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>KIOS K001</kiosknavn>
<serienummer>00 1001001001</serienummer>
</kiosk>
<kiosk>
<kiosknavn>KIOS K002</kiosknavn>
<serienummer>00 2002002002</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
"0020020020 02" 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.GetElement sByTagName("kio sknavn");
foreach(XmlNode node in nodes)
{
if (node.FirstChil d.FirstChild.Va lue == treeView1.Selec tedNode.Text)
{
treeView2.Nodes .Add(node.Outer Xml);
}
}

But it only results in :

Object reference not set to an instance of an object.

Any advice?

Thanks

Nov 17 '05 #1
2 1517
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.FirstChil d.Value == treeView1.Selec tedNode.Text){
treeView2.Nodes .Add(node.Outer Xml);
}
}

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>KIOS K001</kiosknavn>
<serienummer>00 1001001001</serienummer>
</kiosk>
<kiosk>
<kiosknavn>KIOS K002</kiosknavn>
<serienummer>00 2002002002</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
"0020020020 02" 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.GetElement sByTagName("kio sknavn");
foreach(XmlNode node in nodes)
{
if (node.FirstChil d.FirstChild.Va lue == treeView1.Selec tedNode.Text)
{
treeView2.Nodes .Add(node.Outer Xml);
}
}

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>kiok s002</kiosknavn> so
now i have something usable to work with.

thanks
"howard dierking" <ho************ @discussions.mi crosoft.com> skrev i en
meddelelse news:FC******** *************** ***********@mic rosoft.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.FirstChil d.Value == treeView1.Selec tedNode.Text){
treeView2.Nodes .Add(node.Outer Xml);
}
}

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>KIOS K001</kiosknavn>
<serienummer>00 1001001001</serienummer>
</kiosk>
<kiosk>
<kiosknavn>KIOS K002</kiosknavn>
<serienummer>00 2002002002</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
"0020020020 02" 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.GetElement sByTagName("kio sknavn");
foreach(XmlNode node in nodes)
{
if (node.FirstChil d.FirstChild.Va lue ==
treeView1.Selec tedNode.Text)
{
treeView2.Nodes .Add(node.Outer Xml);
}
}

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
6338
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 method would behave like the 'findnodes' XML method in Perl. Namely that you can pass it an xpath statement and it will find nodes that match:...
2
2963
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 XPath expression to select the namespace nodes with prefix "foo"? And what's the XPath expression to select the
2
2336
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 for a way to query XML documents stored in an Oracle 9i database, contained in an unstructured CLOB column, much like one would with a traditional...
2
2786
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 xdoc.LoadXml(Application("MenuXML")) xlist = xdoc.DocumentElement.SelectNodes("//MenuItem")
3
1033
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 remove the xml schema declaration then any of my xpath statements can select any node that I want. Does anybody know what causes this behavior?
5
1728
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 be read when it starts up (based on where it ended). It's just 3 elements, with a short text and a number associated to it. Something like this: ...
2
3474
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 book node should return the author of the selected book (???). But I am getting the first author in the document (Margaret Atwood), not the author...
4
2213
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 : public static Element getElementsBySplitString(String aToSplit, String aSeparator) throws UseXslException {
0
1089
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 Here is what I am guessing - any help would be appreciated
0
7457
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7391
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7651
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7802
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7410
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5962
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5320
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
1010
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
693
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.