Results 1 to 6 of 6

Loop through XML file and get nodes

Threaded View

  1. #1
    Registered User
    Join Date
    01-17-2020
    Location
    Denmark
    MS-Off Ver
    2015
    Posts
    3

    Loop through XML file and get nodes

    Hi

    This is my first post on this website, i've been using the forum alot over the years, but the time has come for me to post a problem that i cant solve myself.

    I'm trying to get some data from a XML file, my issue is that the XML file can vary, but the node names will be the same, but the amount of nodes will vary. I've attached a picture of the issue.

    The Data does not come in the same order as in the XML. I've attached both the excel and the XML that i i've tested it on.

    Img.PNG

    Sub GetAllData()
    
    Dim mainworkbook As Workbook
    Set mainworkbook = ActiveWorkbook
    Set oXMLFile = CreateObject("Microsoft.XMLDOM")
    XMLFileName = ActiveSheet.txtPath.Text
    oXMLFile.Load (XMLFileName)
    Set TitleNodes = oXMLFile.SelectNodes("/MarkupSummary/Markup/Emne/text()")
    Set IntNodes = oXMLFile.SelectNodes("/MarkupSummary/Markup/Forfatter/text()")
    Set SideetiketNodes = oXMLFile.SelectNodes("/MarkupSummary/Markup/Sideetiket/text()")
    Set KommentarerNodes = oXMLFile.SelectNodes("/MarkupSummary/Markup/Kommentarer/text()")
    Set Markup = oXMLFile.SelectNodes("/MarkupSummary")
    
    x = 1
    r = 5
    
    Set list = oXMLFile.SelectNodes("/MarkupSummary")
    
    For i = 0 To (TitleNodes.Length - 1)
    
    Title = TitleNodes(i).NodeValue
    Forfatter = IntNodes(i).NodeValue
    Sideetiket = SideetiketNodes(i).NodeValue
    Kommentarer = KommentarerNodes(i).NodeValue
    Debug.Print i
    
    If Title Like "Bemærkning*" Then
    mainworkbook.ActiveSheet.Range("E" & r).Value = Forfatter
    mainworkbook.ActiveSheet.Range("B" & r).Value = Sideetiket
    mainworkbook.ActiveSheet.Range("C" & r).Value = Title
    mainworkbook.ActiveSheet.Range("D" & r).Value = Kommentarer
    mainworkbook.ActiveSheet.Range("A" & r).Value = x
    
    x = x + 1
    r = r + 1
    End If
    
    Next
    'ActiveSheet.txtPath.Text = ""
    
    End Sub
    I hope some of you have the time and to help me.
    Attached Files Attached Files
    Last edited by AliGW; 01-18-2020 at 10:04 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. find all path between any two nodes in a loop graph
    By sks4444 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-10-2020, 04:12 PM
  2. Finding Values in Nodes and Child Nodes in XML SOAP POST
    By Julesdude in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-25-2018, 11:33 AM
  3. VBA Loop through nodes
    By devatu in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-27-2015, 06:47 AM
  4. How to loop through multiple XML nodes in VBA?
    By mockions in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-03-2015, 01:35 PM
  5. Replies: 1
    Last Post: 11-01-2013, 03:22 PM
  6. Shape Nodes
    By incjourn in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-08-2010, 03:53 PM
  7. Creating Nodes
    By Andy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-10-2005, 03:40 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1