• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 139
  • Last Modified:

Importing XML to database

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.
  • 2
1 Solution
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


fuerteventuraAuthor Commented:
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???????
fuerteventuraAuthor Commented:
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.
PAQed with points refunded (500)

EE Admin

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now