Importing XML to database

Posted on 2007-10-15
Last Modified: 2010-04-30
I need a procedure which will import an XML file into a table.
Basically I want to loop through each node and if the node name matches a field in a table, I want it to import into the table using ADO into an access database). The problem I'm having is when I come across nodes which have a child, it tries to import all the data underneath the parent node into the table, when what I need  it to do is check each of the child nodes, as they contain information which needs importing. How can I do this? I'm guessing that it may involve having a procedure which loops through the nodes and calls itself when it comes across a node which has a child? Hopefully I've explained this clearly enough - please ask me for more info should you require it.
Question by:fuerteventura
    LVL 27

    Expert Comment

    Hello fuerteventura,

    It will help a lot if you can paste a snippet of the XML so that we can get an idea of the structure you are having trouble with.
    Then also paste the snippet of your attempt, which will help us to provide a solution based on your efforts



    Author Comment

    Many thanks for your reply - I have actually managed to work it out this morning! Basically the line of code I needed was as follows:

    oParentNodes As IXMLDOMNode
    Dim ochildnode As IXMLDOMNode
    Dim oChildNodes As IXMLDOMNodeList
    Set oChildNodes = oParentNodes.childNodes

    For i2 = 0 To oChildNodes.length - 1
    Set ochildnode = oChildNodes(i2)
    If ochildnode.baseName & "" > "" Then
    if ochildnode.selectNodes("child::*").length <> 0 Then

    Basically the last line tests if the node has a child node. I'm sure there may be other better ways out there???????

    Author Comment

    I found the answer to the question myself and posted my solution above. In view of this I am happy for the question to be closed, many thanks.
    LVL 1

    Accepted Solution

    PAQed with points refunded (500)

    EE Admin

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
    The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now