B
B-Dog
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>rdbLock</aType>
</LastAlarm>
</Sleep>
Code
Sub ReadXML()
Dim LastAlarm As String
Dim Doc As New XmlDocument
Dim Nav As XPath.XPathNavigator
Dim Iterator As XPath.XPathNodeIterator
'Load document.
Doc.Load(Application.StartupPath & "\" & "sleep.xml")
'Set nav object.
Nav = CType(Doc, XPath.IXPathNavigable).CreateNavigator()
'Set node iterator.
Iterator = Nav.Select("LastAlarm" & "aTime")
'Move to the desired node.
Iterator.MoveNext()
'Get the value of the current node.
LastAlarm = Iterator.Current.Value
End Sub
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>rdbLock</aType>
</LastAlarm>
</Sleep>
Code
Sub ReadXML()
Dim LastAlarm As String
Dim Doc As New XmlDocument
Dim Nav As XPath.XPathNavigator
Dim Iterator As XPath.XPathNodeIterator
'Load document.
Doc.Load(Application.StartupPath & "\" & "sleep.xml")
'Set nav object.
Nav = CType(Doc, XPath.IXPathNavigable).CreateNavigator()
'Set node iterator.
Iterator = Nav.Select("LastAlarm" & "aTime")
'Move to the desired node.
Iterator.MoveNext()
'Get the value of the current node.
LastAlarm = Iterator.Current.Value
End Sub