Vb.Net仅循环通过第一个XML节点多次

时间:2015-03-24 15:58:22

标签: xml vb.net

我有一个VB.net函数,它为xml文档中的每个'property'发送一个HTTP POST请求。但它只能循环通过第一个属性节点,但是有很多次都有节点。即如果有5个属性节点,它将循环通过第一个节点5次。

我不明白为什么它不会继续通过所有属性节点。

vb.net代码。

For Each PropertyNode As XmlNode In Props.SelectNodes("properties/property")
    Try
    'The Function'
    End Try
    Next

阅读此xml文档(道具)。

<?xml version="1.0" encoding="utf-8"?>
<properties>
  <property networkid="" salesbranchid="" lettingsbranchid="" markettype="s" marketingref="-" uripath="" id="5187" created="2015-02-26T09:55:00" edited="2015-03-24T14:55:00" rmstatus="u" reference="RM66998" title="Pea Lane, Caerphilly" classification="Residential" type="7" category="Apartment" status="Available" tenure="Freehold" addressname="75" address1="Pea Lane" area="Caerphilly" city="Caerphilly" county="Glamorgan" postcode1="CF48 " postcode2="5PP" bedrooms="2" receptions="1" bathrooms="2" squarefoot="0.00" price="155446.0000" pricetype="3">
    <office id="2" name="Cathays Terrace" address1="85 Cathays Terrace" city="Cardiff" postcode="CF24 4HT" telephone="029 2022 7080" />
  </property>
  <property networkid="" salesbranchid="" lettingsbranchid="" markettype="l" marketingref="NEWPROP17-L" uripath="" id="5180" created="2015-02-03T16:21:00" edited="2015-03-24T15:01:00" rmstatus="u" reference="NEWPROP17" title="Kings Heath, Roath" summary="A lettings summary" description="A lettings description" classification="Residential" type="7" category="Apartment" status="Available" tenure="12 Months" addressname="44 Only Way" address1="Kings Heath" area="Roath" city="Cardiff" county="Glamorgan" postcode1="CF24 " postcode2="3QD" bedrooms="3" receptions="1" bathrooms="2" squarefoot="0.00" price="500.0000">
  </property>
  <meta totalitems="2" maxpictures="0" maxfloorplans="0">
    <account networkid="" salesbranchid="" lettingsbranchid="" />
  </meta>
</properties>

1 个答案:

答案 0 :(得分:2)

玩这个:

 Private Function GetNodesRecursive(ByRef nNode As System.Xml.XmlNode) As List(Of XmlNode)
        Dim ret As New List(Of XmlNode)
        If nNode.HasChildNodes Then
            For Each item As System.Xml.XmlNode In nNode.ChildNodes
                If item.Name = "id"
                        ret.Add(item)
                   Case Else
                        ret.AddRange(GetNodesRecursive(item))
                End Select
            Next
        End If

        Return ret
    End Function