473,568 Members | 2,898 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(C onfigurationMan ager.AppSetting s("xmlPath").To String() &
"Agency.xml ")

Dim navigator As XPathNavigator = document.Create Navigator()

Dim agencySysNo As Integer = 2

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

Dim nodes As XPathNodeIterat or

nodes = navigator.Selec t(exp)

Dim nodesNavigator As XPathNavigator = nodes.Current

Dim nodesText As XPathNodeIterat or =
nodesNavigator. SelectDescendan ts(XPathNodeTyp e.Text, True)

Response.Write( nodesText.Curre nt.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.13 2" and may be disclosed to third
parties
*************** *************** *************** *************** *************** *
Nov 12 '05 #1
3 1316
Hello!

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

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

XmlNode n = navigator.Selec tSingleNode( 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.Selec tSingleNode( exp )"

Value of type 'System.Xml.XPa th.XPathNavigat or' cannot be converted to
'System.Xml.Xml Node'.

How do I convert to a xmlnode?

Thanks
"Pascal Schmitt" <ne*******@cebr a.nu> wrote in message
news:OZ******** ******@TK2MSFTN GP14.phx.gbl...
Hello!

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

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

XmlNode n = navigator.Selec tSingleNode( 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.Selec tSingleNode( exp )"

Value of type 'System.Xml.XPa th.XPathNavigat or' cannot be converted to
'System.Xml.Xml Node'.


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

XPathNodeIterat or iterator = navigator.Selec t(exp);
while (iterator.MoveM ext()) {
// access iterator.Curren t 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
3951
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 MSXML object then load the XML with a simple objXML.Load(Request). This would give me the XML stream, which I could then manipulate. However,...
3
2527
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 controls are not present nor their valves in Request.Form.AllKeys.
0
2045
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 from database to a VB.net app, they retrieve the database fields as a record set eg. "select name, suburb from myTable"
10
6893
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 creating an AppSettingsReader and using GetValue("ServerName", typeof(String)). That threw an error about key not found. Then i tried...
1
1672
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 converted to a string. the problem now is that i have to retrieve certain values from that xml string in the request field and save the in some other...
15
3511
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 AS IDENTITY ( START WITH 1
1
1431
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 table is initially stored as file.txt.So initially I have to read this file.txt and I have to retrieve the values of each key.Key and value are separated...
2
2227
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 = "hibernatetutorial"; String userName = "root"; String password = "root";
5
3600
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 of hex representations in the form:
0
1439
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 writing a web page in ASP (using C#) that needs to take data from a Database and put it into a ListBox, then have a button retrieve the selected item and...
0
7604
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
7916
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. ...
1
7660
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
7962
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6275
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
5498
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...
0
5217
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
932
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.