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 8238229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:44:23+00:00 2026-06-07T19:44:23+00:00

I have a XML file with a structure similar to this: <egh_eval> <eval_set> <eval_id>FLOAT</eval_id>

  • 0

I have a XML file with a structure similar to this:

<egh_eval>
<eval_set>
    <eval_id>FLOAT</eval_id>
    <eval_d>
        <height>INT</height>
        <weight>INT</weight>
    </eval_d>
    <eval_e>
        <height>INT</height>
        <weight>INT</weight>
    </eval_e>
    <eval_cred>
        <credit>FLOAT</credit>
    </eval_cred>
</eval_set>

I need to parse the complete file and put it in a table. (Note: eval_d and eval_e actually have more than a hundred attributes each). I tried using MSXML2 however I get stuck when I try to parse the file. By using the answers at How to pase XML in VBA and Parse XML in VBA I was able to get there :

Dim fSuccess As Boolean
Dim oDoc As MSXML2.DOMDocument
Dim oRoot As MSXML2.IXMLDOMNode ' Level 0 egh_eval
Dim oChild As MSXML2.IXMLDOMNode ' Level 1 eval_set
Dim oChildren As MSXML2.IXMLDOMNode ' Level 2 eval_id, eval_d, eval_e, eval_cred


Dim domList As MSXML2.IXMLDOMNodeList

Set oDoc = New MSXML2.DOMDocument
oDoc.async = False
oDoc.validateOnParse = False

fSuccess = oDoc.Load(Application.CurrentProject.Path & "\file.xml")

Set oRoot = oDoc.documentElement
Set oChild = oRoot.childNodes(0)
Set oChildren = oChild.childNodes(0)

For i = 0 To oChild.childNodes.length - 1
    For y = 0 To oChildren.childNodes.length - 1
        MsgBox oChildren.nodeName & " : " & oChildren.nodeTypedValue
        oChildren.childNodes.nextNode
    Next
    oChild.childNodes.nextNode
Next

However, instead of giving me the right values, it gives me the float in eval_id 4 times…

Thanks !

EDIT: I am using Microsoft Access 2002 SP3

  • 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-07T19:44:25+00:00Added an answer on June 7, 2026 at 7:44 pm

    Your loop is all wrong. Don’t use a counted loop. There is For Each which will do exactly what you need, and it’s much more readable, too.

    Dim egh_eval As MSXML2.IXMLDOMNode
    Dim eval_set As MSXML2.IXMLDOMNode
    Dim eval_prop As MSXML2.IXMLDOMNode
    
    Set egh_eval = oDoc.documentElement.childNodes(0)
    
    For Each eval_set In egh_eval.childNodes
      If eval_set.nodeType = NODE_ELEMENT Then
        For Each eval_prop In eval_set.childNodes
          If eval_prop.nodeType = NODE_ELEMENT Then
            MsgBox eval_prop.nodeName & " : " & eval_prop.childNodes.length
          End If
        Next eval_prop
      End If
    Next eval_set
    

    When you use childNodes you must check the nodeType property. Comments, text nodes and so on will all be in the list of child nodes, not just element nodes.

    It might be a good idea to look into using XPath to select your elements. Doing this with DOM methods is error-prone and cumbersome. Read up on IXMLDOMNode::selectNodes and IXMLDOMNode::selectSingleNode.

    For Each eval_set In oDoc.selectNodes("/egh_eval/eval_set")
      Set eval_id = eval_set.selectSingleNode("eval_id")
    
      ' always check for empty search result!
      If Not eval_id Is Nothing Then
        MsgBox eval_id.text
        ' ...
      End If
    Next eval_set
    

    Also, on a general note. This:

    fSuccess = oDoc.Load(Application.CurrentProject.Path & "\file.xml")
    

    is actually both not necessary and a bad idea, since you do never seem to check the value of fSuccess). Better:

    Sub LoadAndProcessXml(path As String)
      Dim oDoc As MSXML2.DOMDocument
    
      If oDoc.Load(path) Then
        ProcessXmlFile oDoc
      Else
        ' error handling
      End If
    End Sub
    
    Sub ProcessXml(doc As MSXML2.DOMDocument) 
      ' Process the contents like shown above
    End Sub
    

    Creating multiple subs/functions has several advantages

    • Makes error handling much easier, since every function only has one purpose.
    • You will need less variables, since you can define some variables in the function arguments
    • Code will become more maintainable, since it’s more obvious what 3 short functions do than what one long function does.
    • 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 contains a structure.. In this structure, I have
I have a XML with a structure similar to this: <category> <subCategoryList> <category> </category>
Hi I have big xml file which has a structure similar to the one
I have an xml file nodes structure like this <Employee> <EmpId></EmpId> <EmpName></EmpName> <Salary> <Basic></Basic>
I have an XML file with this structure: <?xml version=1.0 encoding=utf-8 ?> <Photobank> <Landowner
I have an XML file similar in structure to the following: <Parent> <Child>5</Child> <Child>3</Child>
I have an xml file that contains in products. File's structure this: <?xml version=1.0
I have an XML file with this structure: <?xml version=1.0> <person> <element att1=value1 att2=value2>Anonymous</element>
I have an XML file that will be similar to the structure below: <?xml
I have xml file with such structure: ... <outer> ... <inner/> ... </outer> ...

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.