this is probably a silly question and the solution is something i overlooked, but suppose the following xml file (below)
I am iteratiing through the info/test items and then want to iterate again through the test_properties, but I don’t know how.
the properties are never a fixed count, so it could have 1 property or 200
i need the type='” attribute and the value of the property
I use this so far:
Dim Xml_Document As XPathDocument = New XPathDocument("e:\test.xml")
Dim Navigator As XPathNavigator = Xml_Document.CreateNavigator()
Dim ns As XmlNamespaceManager = New XmlNamespaceManager(Navigator.NameTable)
Dim NodeIterator As XPathNodeIterator = Navigator.Select("/info/test")
Try
While NodeIterator.MoveNext()
Dim sanction_id As Integer = CInt(NodeIterator.Current.GetAttribute("id", ns.DefaultNamespace))
Dim clone As XPathNavigator = NodeIterator.Current.Clone()
clone.MoveToFirstChild()
MsgBox(clone.Value)
clone.MoveToNext()
MsgBox(clone.Value)
clone.MoveToNext()
MsgBox(clone.Value)
clone.MoveToNext()
MsgBox(clone.Value)
clone.MoveToNext()
MsgBox(clone.Value)
clone.MoveToNext()
MsgBox(clone.Value)
clone.MoveToNext()
''''''''
' here i want to iterate through test_properties for each property
'''''''
End While
Catch ex As Exception
Console.WriteLine(ex.StackTrace)
End Try
and the xml
<?xml version="1.0" encoding="UTF-8"?>
<info>
<test id="1">
<test_source>ONLINE</test_source>
<test_type><![CDATA[P]]></test_type>
<test_date><![CDATA[2012-02-23]]></test_date>
<test_programme><![CDATA[UK]]></test_programme>
<test_remark><![CDATA[Nice guy]]></test_remark>
<test_key>123456789</test_key>
<test_properties>
<property type="FIRSTNAME"><![CDATA[Robert]]></property>
<property type="MIDDLENAME"><![CDATA[]]></property>
<property type="LASTNAME"><![CDATA[Johnson]]></property>
<property type="GENDER"><![CDATA[M]]></property>
<property type="BIRTHDATE"><![CDATA[1900-01-01]]></property>
</test_properties>
</test>
<test id="2">
<test_source>ONLINE</test_source>
<test_type><![CDATA[P]]></test_type>
<test_date><![CDATA[2012-02-23]]></test_date>
<test_programme><![CDATA[UK]]></test_programme>
<test_remark><![CDATA[Nice girl]]></test_remark>
<test_key>123456789</test_key>
<test_properties>
<property type="FIRSTNAME"><![CDATA[Roberta]]></property>
<property type="MIDDLENAME"><![CDATA[]]></property>
<property type="LASTNAME"><![CDATA[Johnsons]]></property>
<property type="GENDER"><![CDATA[M]]></property>
<property type="BIRTHDATE"><![CDATA[1900-01-01]]></property>
</test_properties>
</test>
</info>
1 Answer