How I can read all Attributes from a XML with VBA?

前端 未结 1 915
挽巷
挽巷 2021-01-13 12:20

I got from a Webservice an XML. I declared it as a \"DOMDocument\". This is my XML. Now I want to read all Attributes named \"ZIP\".



        
相关标签:
1条回答
  • 2021-01-13 12:53

    xmlDoc.SelectSingleNode("//Cities/City") always selects the first node. It cannot magically select the next node every time, it would have to read your mind for that.

    Private Sub Workbook_Open()
      Dim City As String
      Dim xmlUrl As String
      Dim xmlDoc As New DOMDocument
      Dim n As IXMLDOMNode
      Dim i As Long
    
      xmlUrl = "http://localhost:62231/dataHandling.asmx/GetAllCities"
      xmlDoc.async = False
    
      If Not xmlDoc.Load(xmlUrl) Then
        MsgBox "XML LOAD ERROR"
      Else
    
        For Each n In xmlDoc.selectNodes("//Cities/City")
          City = n.Attributes.getNamedItem("ZIP").Text
    
          City = City & " " & n.Text
    
          Tabelle2.Cells(i + 3, 1).Value = City
          i = i + 1
        Next
    
      End If
    
    End Sub
    
    0 讨论(0)
提交回复
热议问题