Need Assistance: VBA parsing through XML

brusk

New Member
Joined
Oct 28, 2014
Messages
30
I need help figuring out how to properly parse through .xml files. Used them plenty just not in code. I'm looking to backup the 100 plus tables I have in excel with the option of importing back in on newer iterations of the workbook due to table structure changes. The .xml file will contain datasets of each table in a single .xml so I'm looking to identify the table name and then pull the records into an array. From there I've got no problems.

.xml example couldn't figure out how to keep formatting on my test .xml when posting it
Code:
Header
root open
  notes
  version
  id
  table open
    table name
    record open
      field 1
      field 2
      field 3
      field 4
    record close
    record open
      field 1
      field 2
      field 3
      field 4
    record close
  table close
  table open
    table name
    record open
      field 1
      field 2
      field 3
      field 4
    record close
    record open
      field 1
      field 2
      field 3
      field 4
    record close
  table close
root close

Currently what I have that I've played with but getting stuck.
Code:
    Dim xDoc As MSXML2.DOMDocument60    
    Dim xNode As MSXML2.IXMLDOMNode
    Dim xRecords As MSXML2.IXMLDOMNodeList
    Dim xElements As MSXML2.IXMLDOMNodeList        


    Set xDoc = New MSXML2.DOMDocument60
    
    If xDoc.Load(ThisWorkbook.Path & "\backup.xml") Then
       ' The document loaded successfully.
       Set xElements = xDoc.getElementsByTagName("Table")
       ' At this point I'm lost and just get errors or nothing on things I've tried
       For Each xNode In xElements.Item(1).ChildNodes
           Debug.Print xNode.Text
       Next
    Else
       ' The document failed to load.
       MsgBox "error loading"
    End If
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top