Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8626723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:06:10+00:00 2026-06-12T08:06:10+00:00

<?xml version=1.0 encoding=UTF-8?> <xa:MeContext id=ABCe0552553> <xa:Data id=ABCe05525531 /> <xa:Data id=1 /> <CustID>Cust1234</CustID> <Name>Smith</Name> <City>New

  • 0
<?xml version="1.0" encoding="UTF-8"?>
<xa:MeContext id="ABCe0552553">
  <xa:Data id="ABCe05525531" />
  <xa:Data id="1" />
  <CustID>Cust1234</CustID>
  <Name>Smith</Name>
  <City>New York</City>
  <Orders>
    <order Orderid="101">
      <Product>MP3 Player</Product>
    </order>
    <order Orderid="102">
      <Product>Radio</Product>
    </order>
  </Orders>
</xa:MeContext>

This well formed XML document feeds to Excel 2007 using MS VBA code. I was successful
with using DOMDocument and IXMLDOMElement to import the Name, City, and Product.
However, the xa:MeContext id, vsData1 id, VsData2 id, CustID, and order Orderid number won’t export to Excel sheet.

Each Excel row has the following headers with data filled from XML document:

MeContextID--vsData1--VsData2--CustID--Name--City--OrderID--Product--OrderID--Product
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:06:12+00:00Added an answer on June 12, 2026 at 8:06 am

    Below are two methods to output the fields you need. Note, that the XML you have posted does not contain the header definitions for namespace “xa:” so is not fully formed XML. I’ve removed them in the example so MSXML2.DOMDocument doesn’t throw a parse error.

    Option Explicit
    Sub XMLMethod()
    Dim XMLString As String
    Dim XMLDoc As Object
    Dim boolValue As Boolean
    Dim xmlDocEl As Object
    Dim xMeContext As Object
    Dim xChild As Object
    Dim xorder As Object
    
    
        XMLString = Sheet1.Range("A1").Value
    
        'Remove xa: in this example
        'reason : "Reference to undeclared namespace prefix: 'xa'."
        'Shouldn't need to do this if full XML is well formed containing correct namespace
        XMLString = Replace(XMLString, "xa:", vbNullString)
    
        Set XMLDoc = CreateObject("MSXML2.DOMDocument")
        'XMLDoc.setProperty "SelectionNamespaces", "xa:"
    
            'XMLDoc.Load = "C:\Users\ooo\Desktop\test.xml" 'load from file
        boolValue = XMLDoc.LoadXML(XMLString)  'load from string
    
        Set xmlDocEl = XMLDoc.DocumentElement
        Set xMeContext = xmlDocEl.SelectSingleNode("//MeContext")
            Debug.Print Split(xMeContext.XML, """")(1)
        For Each xChild In xmlDocEl.ChildNodes
    
            If xChild.NodeName = "Orders" Then
                For Each xorder In xChild.ChildNodes
                    Debug.Print Split(xorder.XML, """")(1)
                    Debug.Print xorder.Text
                Next xorder
    
            ElseIf xChild.Text = "" Then
                Debug.Print Split(xChild.XML, """")(1)
            Else
                Debug.Print xChild.Text
            End If
    
    
        Next xChild
    
        'Output:
        'ABCe0552553
        'ABCe05525531
        '1
        'Cust1234
        'Smith
        'New York
        '101
        'MP3 Player
        '102
        'Radio
    
    
    End Sub
    

    And the following uses regex, which is really only useful if the XML is fixed to exactly your example each time. It’s not really recommended for parsing XML in general unless you want speed over reliability.

    Option Explicit
    
    Sub RegexMethod()
    Dim XMLString As String
    Dim oRegex As Object
    Dim regexArr As Object
    Dim rItem As Object
    
        'Assumes Sheet1.Range("A1").Value holds example XMLString
        XMLString = Sheet1.Range("A1").Value
    
        Set oRegex = CreateObject("vbscript.regexp")
        With oRegex
            .Global = True
            .Pattern = "(id=""|>)(.+?)(""|</)"
            Set regexArr = .Execute(XMLString)
    
            'No lookbehind so replace unwanted chars
            .Pattern = "(id=""|>|""|</)"
            For Each rItem In regexArr
                'Change Debug.Print to fill an array to write to Excel
                Debug.Print .Replace(rItem, vbNullString)
            Next rItem
        End With
    
        'Output:
        'ABCe0552553
        'ABCe05525531
        '1
        'Cust1234
        'Smith
        'New York
        '101
        'MP3 Player
        '102
        'Radio
    
    
    End Sub
    

    EDIT: Slight update to output to array for writing to range

    Option Explicit
    
    Sub RegexMethod()
    Dim XMLString As String
    Dim oRegex As Object
    Dim regexArr As Object
    Dim rItem As Object
    Dim writeArray(1 To 1, 1 To 10) As Variant
    Dim col As Long
    
        'Assumes Sheet1.Range("A1").Value holds example XMLString
        XMLString = Sheet1.Range("A1").Value
    
        Set oRegex = CreateObject("vbscript.regexp")
        With oRegex
            .Global = True
            .Pattern = "(id=""|>)(.+?)(""|</)"
            Set regexArr = .Execute(XMLString)
    
            'No lookbehind so replace unwanted chars
            .Pattern = "(id=""|>|""|</)"
            For Each rItem In regexArr
                'Change Debug.Print to fill an array to write to Excel
                Debug.Print .Replace(rItem, vbNullString)
    
                col = col + 1
                writeArray(1, col) = .Replace(rItem, vbNullString)
            Next rItem
        End With
    
        Sheet1.Range("A5:J5").Value = writeArray
    
    
    End Sub
    
    
    Sub XMLMethod()
    Dim XMLString As String
    Dim XMLDoc As Object
    Dim boolValue As Boolean
    Dim xmlDocEl As Object
    Dim xMeContext As Object
    Dim xChild As Object
    Dim xorder As Object
    Dim writeArray(1 To 1, 1 To 10) As Variant
    Dim col As Long
    
    
        XMLString = Sheet1.Range("A1").Value
    
        'Remove xa: in this example
        'reason : "Reference to undeclared namespace prefix: 'xa'."
        'Shouldn't need to do this if full XML is well formed
        XMLString = Replace(XMLString, "xa:", vbNullString)
    
        Set XMLDoc = CreateObject("MSXML2.DOMDocument")
        'XMLDoc.setProperty "SelectionNamespaces", "xa:"
    
            'XMLDoc.Load = "C:\Users\ooo\Desktop\test.xml" 'load from file
        boolValue = XMLDoc.LoadXML(XMLString)  'load from string
    
        Set xmlDocEl = XMLDoc.DocumentElement
        Set xMeContext = xmlDocEl.SelectSingleNode("//MeContext")
            'Debug.Print Split(xMeContext.XML, """")(1)
            col = col + 1
            writeArray(1, col) = Split(xMeContext.XML, """")(1)
        For Each xChild In xmlDocEl.ChildNodes
    
            If xChild.NodeName = "Orders" Then
                For Each xorder In xChild.ChildNodes
                    col = col + 1
                    'Debug.Print Split(xorder.XML, """")(1)
                    writeArray(1, col) = Split(xorder.XML, """")(1)
                    col = col + 1
                    'Debug.Print xorder.Text
                    writeArray(1, col) = xorder.Text
                Next xorder
            ElseIf xChild.Text = "" Then
                col = col + 1
                'Debug.Print Split(xChild.XML, """")(1)
                writeArray(1, col) = Split(xChild.XML, """")(1)
            Else
                col = col + 1
                'debug.Print xChild.Text
                writeArray(1, col) = xChild.Text
            End If
    
    
        Next xChild
    
        Sheet1.Range("A5:J5").Value = writeArray
    
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML file that looks like <?xml version='1.0' encoding='UTF-8'?> <root> <node name=foo1
My XML looks like this: <?xml version = 1.0 encoding = utf-8?> <gallery> <name>Rosie's
I have the following XML Document: <?xml version=\1.0\ encoding=\UTF-8\?> <atom:entry xmlns:atom=\http://www.w3.org/2005/Atom\ xmlns:apps=\http://schemas.google.com/apps/2006\ xmlns:gd=\http://schemas.google.com/g/2005\> <apps:property
Here's the XML: <?xml version='1.0' encoding='UTF-8' standalone='yes' ?> <feed xmlns=http://www.w3.org/2005/Atom xmlns:dc=http://purl.org/dc/elements/1.1/> <title>Rated Images</title> <link
I have an getting an xml response on this format <?xml version=\1.0\ encoding=\utf-8\?>\r\n <PlatformResponse
I am trying to parse the following XML with javascript: <?xml version='1.0' encoding='UTF-8'?> <ResultSet>
This is my xhtml code : <?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html PUBLIC -//W3C//DTD
I have the following simplified XML: <?xml version="1.0" encoding="UTF-8" ?> <MATMAS05> <IDOC BEGIN="1"> <E1MARAM
I have the following simplified XML structure: <?xml version="1.0" encoding="UTF-8" ?> <INVOIC02> <IDOC BEGIN="1">
My Xml Should look like: <?xml version=1.0 encoding=UTF-8 standalone=yes?> <results> <version>1.0</version> <status>ok</status> <lastUpdate>2011-11-21 09:23:59.0</lastUpdate>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.