473,811 Members | 2,856 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Read XML Help.

I'm trying to read two nodes in an xml file that I'm using to store setting
but I'm having a hard time trying to read the values of two nodes. Below I
can read one node but I need to be able to grab both values and I can't seem
to figure it out, just a bigginer. I'm able to grab aTime but can't get the
aType value. Should I create a second routine or is there something I can
stick in this to make it work for me. I just want those two value, the file
never changes just the values. Thanks

XML File

- <Sleep>
- <LastAlarm>
<aTime>5/28/2004 2:29:00 PM</aTime>
<aType>rdbLoc k</aType>
</LastAlarm>
</Sleep>
Code

Sub ReadXML()

Dim LastAlarm As String

Dim Doc As New XmlDocument

Dim Nav As XPath.XPathNavi gator

Dim Iterator As XPath.XPathNode Iterator

'Load document.

Doc.Load(Applic ation.StartupPa th & "\" & "sleep.xml" )

'Set nav object.

Nav = CType(Doc, XPath.IXPathNav igable).CreateN avigator()

'Set node iterator.

Iterator = Nav.Select("Las tAlarm" & "aTime")

'Move to the desired node.

Iterator.MoveNe xt()

'Get the value of the current node.

LastAlarm = Iterator.Curren t.Value

End Sub
Nov 20 '05 #1
9 1330
In article <eN************ **@TK2MSFTNGP11 .phx.gbl>, bd***@hotmail.c om
says...
I'm trying to read two nodes in an xml file that I'm using to store setting
but I'm having a hard time trying to read the values of two nodes. Below I
can read one node but I need to be able to grab both values and I can't seem
to figure it out, just a bigginer. I'm able to grab aTime but can't get the
aType value. Should I create a second routine or is there something I can
stick in this to make it work for me. I just want those two value, the file
never changes just the values. Thanks


An XPath query would probably be quicker:

http://www.w3schools.com/xpath/xpath_syntax.asp

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele
Nov 20 '05 #2
dim aTime as string = doc.documentele ment.selectsing lenode("//aTime").valu
dim aType as string = doc.documentele ment.selectsing lenode("//aType").valu
----- B-Dog wrote: ----

I'm trying to read two nodes in an xml file that I'm using to store settin
but I'm having a hard time trying to read the values of two nodes. Below
can read one node but I need to be able to grab both values and I can't see
to figure it out, just a bigginer. I'm able to grab aTime but can't get th
aType value. Should I create a second routine or is there something I ca
stick in this to make it work for me. I just want those two value, the fil
never changes just the values. Thank

XML Fil

- <Sleep
- <LastAlarm><aTi me>5/28/2004 2:29:00 PM</aTime><aType>rd bLock</aType></LastAlarm></Sleep
Cod

Sub ReadXML(

Dim LastAlarm As Strin

Dim Doc As New XmlDocumen

Dim Nav As XPath.XPathNavi gato

Dim Iterator As XPath.XPathNode Iterato

'Load document

Doc.Load(Applic ation.StartupPa th & "\" & "sleep.xml"

'Set nav object

Nav = CType(Doc, XPath.IXPathNav igable).CreateN avigator(

'Set node iterator

Iterator = Nav.Select("Las tAlarm" & "aTime"

'Move to the desired node

Iterator.MoveNe xt(

'Get the value of the current node

LastAlarm = Iterator.Curren t.Valu

End Su

Nov 20 '05 #3
Thanks for the link I'll have a look.

"Patrick Steele [MVP]" <pa*****@mvps.o rg> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
In article <eN************ **@TK2MSFTNGP11 .phx.gbl>, bd***@hotmail.c om
says...
I'm trying to read two nodes in an xml file that I'm using to store setting but I'm having a hard time trying to read the values of two nodes. Below I can read one node but I need to be able to grab both values and I can't seem to figure it out, just a bigginer. I'm able to grab aTime but can't get the aType value. Should I create a second routine or is there something I can stick in this to make it work for me. I just want those two value, the file never changes just the values. Thanks


An XPath query would probably be quicker:

http://www.w3schools.com/xpath/xpath_syntax.asp

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele

Nov 20 '05 #4
That is what I needed tman, I'll try it

Thanks!

"tMan" <an*******@disc ussions.microso ft.com> wrote in message
news:2E******** *************** ***********@mic rosoft.com...
dim aTime as string = doc.documentele ment.selectsing lenode("//aTime").value dim aType as string = doc.documentele ment.selectsing lenode("//aType").value

----- B-Dog wrote: -----

I'm trying to read two nodes in an xml file that I'm using to store setting but I'm having a hard time trying to read the values of two nodes. Below I can read one node but I need to be able to grab both values and I can't seem to figure it out, just a bigginer. I'm able to grab aTime but can't get the aType value. Should I create a second routine or is there something I can stick in this to make it work for me. I just want those two value, the file never changes just the values. Thanks

XML File

- <Sleep>
- <LastAlarm><aTi me>5/28/2004 2:29:00 PM</aTime><aType>rd bLock</aType></LastAlarm></Sleep> Code

Sub ReadXML()

Dim LastAlarm As String

Dim Doc As New XmlDocument

Dim Nav As XPath.XPathNavi gator

Dim Iterator As XPath.XPathNode Iterator

'Load document.

Doc.Load(Applic ation.StartupPa th & "\" & "sleep.xml" )

'Set nav object.

Nav = CType(Doc, XPath.IXPathNav igable).CreateN avigator()

'Set node iterator.

Iterator = Nav.Select("Las tAlarm" & "aTime")

'Move to the desired node.

Iterator.MoveNe xt()

'Get the value of the current node.

LastAlarm = Iterator.Curren t.Value

End Sub

Nov 20 '05 #5
whats the exception message?
Nov 20 '05 #6
oh ok..my bad!
instead of value use innertext property

Dim aTime As String = Doc.DocumentEle ment.SelectSing leNode("//aTime").InnerTe x

Dim aType As String = Doc.DocumentEle ment.SelectSing leNode("/aType").InnerTe xt
Nov 20 '05 #7
Hmnn, I tried this below but doesn't give me a value, only my error message
Try

Dim Doc As New XmlDocument

'Load document.

Doc.Load(Applic ation.StartupPa th & "\" & "sleep.xml" )

Dim aTime As String = Doc.DocumentEle ment.SelectSing leNode("//aTime").Value

Dim aType As String = Doc.DocumentEle ment.SelectSing leNode("/aType").Value

MsgBox(aTime)

Catch ex As Exception

MsgBox("error")

End Try

"tMan" <an*******@disc ussions.microso ft.com> wrote in message
news:2E******** *************** ***********@mic rosoft.com...
dim aTime as string = doc.documentele ment.selectsing lenode("//aTime").value dim aType as string = doc.documentele ment.selectsing lenode("//aType").value

----- B-Dog wrote: -----

I'm trying to read two nodes in an xml file that I'm using to store setting but I'm having a hard time trying to read the values of two nodes. Below I can read one node but I need to be able to grab both values and I can't seem to figure it out, just a bigginer. I'm able to grab aTime but can't get the aType value. Should I create a second routine or is there something I can stick in this to make it work for me. I just want those two value, the file never changes just the values. Thanks

XML File

- <Sleep>
- <LastAlarm><aTi me>5/28/2004 2:29:00 PM</aTime><aType>rd bLock</aType></LastAlarm></Sleep> Code

Sub ReadXML()

Dim LastAlarm As String

Dim Doc As New XmlDocument

Dim Nav As XPath.XPathNavi gator

Dim Iterator As XPath.XPathNode Iterator

'Load document.

Doc.Load(Applic ation.StartupPa th & "\" & "sleep.xml" )

'Set nav object.

Nav = CType(Doc, XPath.IXPathNav igable).CreateN avigator()

'Set node iterator.

Iterator = Nav.Select("Las tAlarm" & "aTime")

'Move to the desired node.

Iterator.MoveNe xt()

'Get the value of the current node.

LastAlarm = Iterator.Curren t.Value

End Sub

Nov 20 '05 #8
Hi B-Dog,

I thought I would put in my 2 cents.

http://kjmsolutions.com/xmlsettings.htm
I'm trying to read two nodes in an xml file that I'm using to store setting but I'm having a hard time trying to read the values of two nodes.

Nov 20 '05 #9
Thanks guys for all the help!

"scorpion53 061" <sc************ @nospamhereever yahoo.com> wrote in message
news:OE******** ******@tk2msftn gp13.phx.gbl...
Hi B-Dog,

I thought I would put in my 2 cents.

http://kjmsolutions.com/xmlsettings.htm
I'm trying to read two nodes in an xml file that I'm using to store

setting
but I'm having a hard time trying to read the values of two nodes.


Nov 20 '05 #10

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

Similar topics

10
2291
by: ZafT | last post by:
Thanks in advance for any tips that might get me going in the right direction. I am working on a simple exercise for school that is supposed to use read to read a file (about 10 MB). I am supposed to change the buffer size and see how this affects the read time. In other words, the buffer is supposed to limit how much of the file gets read per call, and cause some change in speed. I am supposed to do the same with fread as well, but...
1
3446
by: Chua Wen Ching | last post by:
Hi there, I have some problems when reading XML file. 1. First this, is what i did, cause i can't seem to read "sub elements or tags" values, so i place those values into attributes like this. Before: ----------
15
4757
by: ruca | last post by:
Hi, Can I read a .TXT File to a DataSet? How can I do that? I want to read his lines to a DropDownList. This lines are the names of employees that I export from an application that I have. I export them to a .txt file and I want to "work" with this employees in my aspx page. Can you help me? It's a little bit strange, but it's what I need. :)
3
4020
by: Dave Coate | last post by:
Hello again, I am going to re-post a question. I got some excellent suggestions from Rob and Mattias on this but their ideas did not solve the problem. Here is the original post: ***************************************************** I am looking for a way to 'override' file security and read the Owner of a file to which I have no access. I am a system administrator, as such I have administrative rights to all the computers in the...
8
2345
by: dosworldguy | last post by:
I have been having a very peculiar issue from a long time. I have an application where multiple clients read from a shared set of files. When a record is changed, sometimes the win9x clients still read the old data (if it was read earlier) and this is causing data corruption. WinNT clients inlcuding windows2000 & XP do not have this issue. The program is complied in VC++, console mode. I am unable to understand the cause. I flush the...
8
2947
by: Mr. SweatyFinger | last post by:
where have they all gone. alt.suicide? alt.findContol.then.slit.your.own.throat?
9
7391
by: flebber | last post by:
I was working at creating a simple program that would read the content of a playlist file( in this case *.k3b") and write it out . the compressed "*.k3b" file has two file and the one I was trying to read was maindata.xml . I cannot however seem to use the gzip module correctly. Have tried the program 2 ways for no success, any ideas would be appreciated. Attempt 1 #!/usr/bin/python
9
2258
by: Hollywood | last post by:
Hello members of the comp.lang.c++, My log file is made of a set of 1000 following lines kind: 21/09/07 13:49:56,MW.SET.D_IGLS,2.000000 21/09/07 13:49:56,MW.SET.GNP_NT,7.000000 ..... commas ',' are used as field separators (data, name, value).
3
13267
by: Rahul Babbar | last post by:
Hi, I had the following doubts about the "For Read Only" clause. 1. How does a "for Read only" clause improve the performance? 2. How does a "for Read only" clause compare with "With UR" clause in performance? Which is faster? Can someone clarify on that?
6
418
by: rohit | last post by:
Hi All, I am new to C language.I want to read integers from a text file and want to do some operation in the main program.To be more specific I need to multiply each of these integers with another set of integers stored in an array.It would be a great help if you could provide some code for it.I tried the function fscanf but by that I am able to read only the first integer of the text file.Please help me.
0
9722
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9603
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10379
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10393
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10124
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7664
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3863
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.