read .xml file line by line

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

read .xml file line by line

Post by sal21 »

Code: Select all


Option Explicit
Sub ParseXmlDocument()

   Dim doc As New MSXML2.DOMDocument
   Dim success As Boolean

   success = doc.Load("C:\Lavori_Vb6\TEST_MAPPA" & "\test.xml")
   If success = False Then
      MsgBox doc.parseError.reason
   Else
      Dim nodeList As MSXML2.IXMLDOMNodeList

      Set nodeList = doc.SelectNodes("/comuni")

      If Not nodeList Is Nothing Then
      
         Dim node As MSXML2.IXMLDOMNode
         Dim name As String
         Dim value As String

         For Each node In nodeList
         
            Debug.Print node.Attributes.getNamedItem("comune").Text
            'name = node.SelectSingleNode("@id").Text
            'value = node.SelectSingleNode("@value").Text
            
         Next node
         
      End If
      
   End If
   
End Sub
i just have set a reference xml3, ver 3.0
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: read .xml file line by line

Post by HansV »

What is your question?
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

Re: read .xml file line by line

Post by sal21 »

HansV wrote:
02 Dec 2022, 08:11
What is your question?
with the code posted have error....

i need to get each value in bold from block:

...
<comune>
<campo nome="id">1001</campo>
<campo nome="id_regione">1</campo>
<campo nome="id_provincia">1</campo>
<campo nome="nome">Agliè</campo>
<campo nome="capoluogo_provincia">0</campo>
<campo nome="codice_catastale">A074</campo>
<campo nome="latitudine">45.364155</campo>
<campo nome="longitudine">7.768627</campo>
</comune>

...

User avatar
SpeakEasy
4StarLounger
Posts: 536
Joined: 27 Jun 2021, 10:46

Re: read .xml file line by line

Post by SpeakEasy »

Code: Select all

   Dim doc As New MSXML2.DOMDocument
   Dim success As Boolean

   success = doc.Load("C:\Lavori_Vb6\TEST_MAPPA" & "\test.xml")
   If success = False Then
      MsgBox doc.parseError.reason
   Else
      Dim nodeList As MSXML2.IXMLDOMNodeList
      
      Set nodeList = doc.selectNodes("/comuni/comune")

      If Not nodeList Is Nothing Then
      
         Dim node As MSXML2.IXMLDOMNode
         Dim childnode As MSXML2.IXMLDOMNode
         Dim name As String
         Dim value As String

         For Each node In nodeList
            For Each childnode In node.childNodes
                Debug.Print childnode.Attributes(0).Text, childnode.Text
            Next
         Next node
      End If
         

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

Re: read .xml file line by line

Post by sal21 »

SpeakEasy wrote:
02 Dec 2022, 13:45

Code: Select all

   Dim doc As New MSXML2.DOMDocument
   Dim success As Boolean

   success = doc.Load("C:\Lavori_Vb6\TEST_MAPPA" & "\test.xml")
   If success = False Then
      MsgBox doc.parseError.reason
   Else
      Dim nodeList As MSXML2.IXMLDOMNodeList
      
      Set nodeList = doc.selectNodes("/comuni/comune")

      If Not nodeList Is Nothing Then
      
         Dim node As MSXML2.IXMLDOMNode
         Dim childnode As MSXML2.IXMLDOMNode
         Dim name As String
         Dim value As String

         For Each node In nodeList
            For Each childnode In node.childNodes
                Debug.Print childnode.Attributes(0).Text, childnode.Text
            Next
         Next node
      End If
         
tks for code.

missing

end if

and sub

but in othe cse resolved.

User avatar
SpeakEasy
4StarLounger
Posts: 536
Joined: 27 Jun 2021, 10:46

Re: read .xml file line by line

Post by SpeakEasy »

>missing
That''s me not paying full attention when I copy and pasted from the IDE

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

Re: read .xml file line by line

Post by sal21 »

SpeakEasy wrote:
02 Dec 2022, 16:55
>missing
That''s me not paying full attention when I copy and pasted from the IDE
no prob, bro!