jes12345
asked on
XML navigation in VB .NET
I am new to xml navigation in .NET so I have a fairly basic question I hope someone can help me with.
I have a xml file with a similar structure as shown below. I iterate through the node list and find the node I need based on field1. However I am not sure how I can reach the value I need which is field2.
Maybe it is a better approach to set the navigator to ""/message/value" and then retreive each child individually. If so any advise of the syntax will be very good.
Thanks J
I have a xml file with a similar structure as shown below. I iterate through the node list and find the node I need based on field1. However I am not sure how I can reach the value I need which is field2.
Maybe it is a better approach to set the navigator to ""/message/value" and then retreive each child individually. If so any advise of the syntax will be very good.
Thanks J
<?xml version="1.0" encoding="iso-8859-1"?>
<message>
<value>
<field1>0001</field1>
<field2>This is the text I need for 0001</field2>
</value>
<value>
<field1>0002</field1>
<field2>This is the text I need for 0002</field2>
</value>
</message>
Dim xpathDoc As XPathDocument
Dim xmlNav As XPathNavigator
Dim xmlNI As XPathNodeIterator
Dim _strValue As String = ""
xpathDoc = New XPathDocument("C:\test.xml")
xmlNav = xpathDoc.CreateNavigator()
xmlNI = xmlNav.Select("/message/value/field1")
While (xmlNI.MoveNext())
If xmlNI.Current.Value = "0001" Then
_strValue= some code here to retrieve value "This is the text I need 0001"
Exit While
End If
End While
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Woked like a charm - many thanks for the advise! J
ASKER
I think it was perfect:)
ASKER
Thanks J