473,503 Members | 3,171 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Retrieving values from XML file

I want to be able access an xml file using an XPath? query to go to a
specific node. Once I have that node I want to be able to retrieve the value
of an attribute. Can't seem to get this working using the 2.0 Framework.
Here's a sample of the XML

<Agency>

<vu_Agency AgencySysNo="1" Name="Dept 1"/>

<vu_Agency AgencySysNo="2" Name="Dept 2"/>

</Agency>
The code I'm playing with is...

Dim document As XPathDocument = New
XPathDocument(ConfigurationManager.AppSettings("xm lPath").ToString() &
"Agency.xml")

Dim navigator As XPathNavigator = document.CreateNavigator()

Dim agencySysNo As Integer = 2

Dim exp As XPathExpression =
navigator.Compile("/Agency/vu_Agency[@AgencySysNo=" & agencySysNo & "]")

Dim nodes As XPathNodeIterator

nodes = navigator.Select(exp)

Dim nodesNavigator As XPathNavigator = nodes.Current

Dim nodesText As XPathNodeIterator =
nodesNavigator.SelectDescendants(XPathNodeType.Tex t, True)

Response.Write(nodesText.Current.Value)

Thanks for any help....

--
Mike Gasperino
Sr. Software Developer
office: 919-807-2310

************************************************** **************************
E-mail correspondence to and from this address may be subject to the North
Carolina Public Records Law "NCGS.Ch.132" and may be disclosed to third
parties
************************************************** **************************
Nov 12 '05 #1
3 1311
Hello!

Try this (it is C#, I'm not sure of the VB syntax :o)

....
XPathExpression exp =
navigator.Compile(string.Format("/Agency/vu_Agency[@AgencySysNo='{0}']/@Dept",
agencySysNo ));

XmlNode n = navigator.SelectSingleNode( exp )
if( n != null )
Response.Write( ((XmlAttribute) n).Value );
The XPath Expression directly selects the Attribute (I suppose it is
unique?) and returns null/Nothing if it wasn't found. If it retourned
something, it is the Attribute, so I cast it as an XmlAttribute and
return its Value.
--
Pascal Schmitt
Nov 12 '05 #2
Hey Pascal,

I get a pre-compile message on this line of code "XmlNode n =
navigator.SelectSingleNode( exp )"

Value of type 'System.Xml.XPath.XPathNavigator' cannot be converted to
'System.Xml.XmlNode'.

How do I convert to a xmlnode?

Thanks
"Pascal Schmitt" <ne*******@cebra.nu> wrote in message
news:OZ**************@TK2MSFTNGP14.phx.gbl...
Hello!

Try this (it is C#, I'm not sure of the VB syntax :o)

...
XPathExpression exp =
navigator.Compile(string.Format("/Agency/vu_Agency[@AgencySysNo='{0}']/@Dept",
agencySysNo ));

XmlNode n = navigator.SelectSingleNode( exp )
if( n != null )
Response.Write( ((XmlAttribute) n).Value );
The XPath Expression directly selects the Attribute (I suppose it is
unique?) and returns null/Nothing if it wasn't found. If it retourned
something, it is the Attribute, so I cast it as an XmlAttribute and return
its Value.
--
Pascal Schmitt

Nov 12 '05 #3


Mike wrote:

I get a pre-compile message on this line of code "XmlNode n =
navigator.SelectSingleNode( exp )"

Value of type 'System.Xml.XPath.XPathNavigator' cannot be converted to
'System.Xml.XmlNode'.


If you have an XPathNavigator then there is (at least in .NET 1.x) no
SelectSingleNode method, there is a Select method however so you are
likely looking for something as

XPathNodeIterator iterator = navigator.Select(exp);
while (iterator.MoveMext()) {
// access iterator.Current here
}
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #4

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

Similar topics

13
3943
by: RHPT | last post by:
I am wanting to capture the XML posted by an InfoPath form with .NET, but I cannot figure out how to capture the XML stream sent back by the InfoPath form. With Classic ASP, I could just create an...
3
2525
by: Dotnet Gruven | last post by:
I've built a WebForm with a Table added dynamically in Page_Load when IsPostBack is false. The table includes a couple of TextBoxes, RadioButtonLists and CheckboxLists. On postback, those...
0
2022
by: Andy | last post by:
Hi All. I'm working for a company that has set out a guideline for retrieving data from a database. Nobody can explain to me the reason for the following. When retrieving a set of records...
10
6882
by: Dan | last post by:
I use the settings grid to create a setting named "ServerName". Now i want to retrieve it in code and i can't figure out how. This should be incredibly obvious but i cant get it. I have tried...
1
1668
by: lmwasisebe | last post by:
hie guys i having problems retrieving xml values, this is the structure of the problem: I have a database with the following fields, 1)id 2)state 3)request. the request field contains a xml file...
15
3502
by: gunnar.sigurjonsson | last post by:
I´m having some problem retrieving identity value from my newly inserted row into a view. I have two tables T1 and T2 which I define as following CREATE TABLE T1 ( id BIGINT GENERATED ALWAYS...
1
1428
by: mickey22 | last post by:
Hi all, I have a txt file in the following format and have to retrieve the values when I give the key. For example: (key) (value) File = c:/a.hdr Range = 10 Reference Value=100 This...
2
2215
by: shivapadma | last post by:
i have inserted the image into database using the following code String driverName = "com.mysql.jdbc.Driver"; String url = "jdbc:mysql://localhost:3306/"; String dbName =...
5
3598
by: Filipe Teixeira | last post by:
Hi. I have to open a binary file from an old computer and recover the information stored (or at least try to). I use: f=open('file.bin','rb') a=f.read() f.close() a in now a string full...
0
1432
by: Phijo | last post by:
Hello, I'm a Java developer but brand new to ASP (i have done some of the tutorials) so I have some ASP programming background however I cannot find the cause or the fix to this problem. I am...
0
7188
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,...
0
7063
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
7313
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
5558
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,...
1
4987
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...
0
4663
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3156
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1489
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
366
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...

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.