473,385 Members | 1,843 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,385 software developers and data experts.

Problem querying for node by attribute

I have the following XML document, loaded in MyDoc (declared as
XML.XMLDocument):

<configuration>
<appSettings>
<add key="LastUpdate" value="9/3/2003" />
</appSettings>
</configuration>

I'm trying to query the document for the node containing the attribute
key="LastUpdate" (and I know there will only be one element with this
attribute). I tried the following code:

dim aNode as XML.XMLNode
aNode = MyDoc.SelectSingleNode("@key='LastUpdate'")

but I get a run-time exception: "The expression passed to this method should
result in a NodeSet."

So, I tried:

dim manyNodes as XML.XMLNodeList
manyNodes = MyDoc.SelectNodes("@key='LastUpdate'")

Same result. I'm using VB.Net 2003.

Can someone please point me in the right direction?
Nov 12 '05 #1
2 3360
Do you get the right result when you try it with this XPath-expression:
XmlNode nd = doc.SelectSingleNode("//add[@key='LastUpdate']");
"Richard L Rosenheim" <ri*****@rlr.com> schrieb im Newsbeitrag
news:%2***************@TK2MSFTNGP09.phx.gbl...
I have the following XML document, loaded in MyDoc (declared as
XML.XMLDocument):

<configuration>
<appSettings>
<add key="LastUpdate" value="9/3/2003" />
</appSettings>
</configuration>

I'm trying to query the document for the node containing the attribute
key="LastUpdate" (and I know there will only be one element with this
attribute). I tried the following code:

dim aNode as XML.XMLNode
aNode = MyDoc.SelectSingleNode("@key='LastUpdate'")

but I get a run-time exception: "The expression passed to this method
should
result in a NodeSet."

So, I tried:

dim manyNodes as XML.XMLNodeList
manyNodes = MyDoc.SelectNodes("@key='LastUpdate'")

Same result. I'm using VB.Net 2003.

Can someone please point me in the right direction?

Nov 12 '05 #2
Yes, that worked. Thanks.

Richard
"Albert Greinöcker" <al****************@uibk.ac.at> wrote in message
news:Vl*******************@news.chello.at...
Do you get the right result when you try it with this XPath-expression:
XmlNode nd = doc.SelectSingleNode("//add[@key='LastUpdate']");
"Richard L Rosenheim" <ri*****@rlr.com> schrieb im Newsbeitrag
news:%2***************@TK2MSFTNGP09.phx.gbl...
I have the following XML document, loaded in MyDoc (declared as
XML.XMLDocument):

<configuration>
<appSettings>
<add key="LastUpdate" value="9/3/2003" />
</appSettings>
</configuration>

I'm trying to query the document for the node containing the attribute
key="LastUpdate" (and I know there will only be one element with this
attribute). I tried the following code:

dim aNode as XML.XMLNode
aNode = MyDoc.SelectSingleNode("@key='LastUpdate'")

but I get a run-time exception: "The expression passed to this method
should
result in a NodeSet."

So, I tried:

dim manyNodes as XML.XMLNodeList
manyNodes = MyDoc.SelectNodes("@key='LastUpdate'")

Same result. I'm using VB.Net 2003.

Can someone please point me in the right direction?


Nov 12 '05 #3

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

Similar topics

2
by: poofpoof | last post by:
Dear Experts, I have some problems with XSLT recursivity... here what I want to do XML part : ---------- <struct>
1
by: infiniti | last post by:
Hi, I am trying to transform this xml section using xsl, but there is a glitch in the xsl file which I do not know how to rectify. Any help is appreciated. XML: <?xml version="1.0"...
1
by: John Wilhelm | last post by:
I'm having a problem in by VB.net 2005 application. When i try to get a node from my app.config file the node come back with "nothing". The xmldocment loads OK, but I can't retrive a node. The...
5
by: christian.eickhoff | last post by:
Hello Everybody, am currently developing some coder for XML files but am facing some minor problem which might be very easy to solve for XERCES experts. For my coder it is indispensable to...
27
by: comp.lang.tcl | last post by:
My TCL proc, XML_GET_ALL_ELEMENT_ATTRS, is supposed to convert an XML file into a TCL list as follows: attr1 {val1} attr2 {val2} ... attrN {valN} This is the TCL code that does this: set...
2
by: nvidia1 | last post by:
Hi this is my first post but so far this is pretty good site. I have a file called index.html with the following code: <!-- index.html --> <html> <head><title>Student Registration...
1
by: Tedros.G | last post by:
Hi I have an attribute the appears in both the root node and child node for example, below the attribute VERSION appears in the rood node (PRODMSG ) and a child node (OPERATION ) ================...
11
by: =?ISO-8859-1?Q?Jean=2DFran=E7ois_Michaud?= | last post by:
Context: I'm trying to compare XML tree fragments and I'm doing so by outputting the attributes of each element in the tree and outputting it to a string then normalizing the strings. Then I'm...
0
by: gnewsgroup | last post by:
I need to bind *some* nodes of an xml document to an asp.net Menu control. The problem is that the XML document uses the same node name and attribute name for for the entire document among all...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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...

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.