【问题标题】:Vb.Net only looping through 1st XML node mutiple timeVb.Net 仅多次循环通过第一个 XML 节点
【发布时间】:2015-03-25 00:41:06
【问题描述】:

我有一个 VB.net 函数,它为 xml 文档中的每个“属性”发送 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>

【问题讨论】:

    标签: xml vb.net


    【解决方案1】:

    玩这个:

     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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-16
      • 1970-01-01
      • 1970-01-01
      • 2013-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多