Results 1 to 3 of 3

Thread: [RESOLVED] Populating XML DOM content to List Box

Threaded View

  1. #1

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    176

    Resolved [RESOLVED] Populating XML DOM content to List Box

    Hi there,

    I have an XML file and structured like this:

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    
    <applications>
        <app id="b461ae4a" valid="1" company="Orange Inc." appname="None" user="tommy" description="Test" note="None" />
        <app id="1c94395b" valid="0" company="Lemon Inc." appname="None" user="admin" description="Test" note="None" />
        <app id="d65k274p" valid="0" company="Lemon Inc." appname="None" user="admin" description="Test" note="None" />
    </applications>


    And I wish to be able to populate / enumerate field by filed to List Box, but I'm missing something out and my loop is getting errors:

    Code:
    Dim xmlDoc As Object
    Dim xmlNode As Object
    Dim xmlNodes As Object
    Dim stXmlFile as String
    Dim itCnt As Integer
    
    stXmlFile = "C:\apps.xml"
    
    Set xmlDoc = CreateObject("Microsoft.XMLDOM")
     
    xmlDoc.async = "False"
    
    If Not xmlDoc.Load(stXmlFile) Then
      Set xmlNodes = Nothing
      Set xmlDoc = Nothing
      Debug.Print "Error"
      Exit Sub
     End If
    
    For itCnt = 0 To xmlDoc.selectNodes("//applications").length
     ListBox.AddItem xmlDoc.selectNodes("//applications//app").Item(itCnt).selectSingleNode("id").Text
     ListBox.AddItem xmlDoc.selectNodes("//applications//app").Item(itCnt).selectSingleNode("valid").Text
     ListBox.AddItem xmlDoc.selectNodes("//applications//app").Item(itCnt).selectSingleNode("company").Text
     ' ... etc...
    Next itCnt
    also tried like this:

    Code:
    Set xmlNodes = xmlDoc.SelectNodes("//applications//app")
            
    For Each xmlNode In xmlNodes
     ListBox.AddItem xmlNodes.getAttribute("id")
     ListBox.AddItem xmlNodes.getAttribute("valid")
     ListBox.AddItem xmlNodes.getAttribute("company")
    Next
    But without any luck.

    Any help would be highly appreciated!

    Kind regards,
    Viktor
    Last edited by beic; Apr 15th, 2020 at 09:05 AM. Reason: typo

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width