• 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.
0
fuerteventura
Asked:
fuerteventura
  • 2
1 Solution
 
DabasCommented:
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

Regards,

Dabas
0
 
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???????
0
 
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.
0
 
Computer101Commented:
PAQed with points refunded (500)

Computer101
EE Admin
0

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