Retrieve parent - child relation from a XML file

Hi experts,

I've got this XML file that represents a nested parent-child relationship between folders.

I'd like to save these relationships in to my database but before I can save them I have to retrieve them. And I have little knowledge reading XML in VBS.

My table is simple it has these fields :

ID (record identifier)
parentID
folderID
folderName

I've got a XML structure like in the image beneath. As you can see I've simplified it caling the folders grandmother, parent1, child1,2:

xml.JPG
The desired result I like to be able to collect in my table should be something like:

table.JPG  

But the DB part is no problem and can be done by myself.
LVL 1
SteynskAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Robert SchuttSoftware EngineerCommented:
Based on the script from your previous question http:/Q_28495636.html and assuming ID is automatically generated:
Option Explicit

Dim msg, xmlDOM, folder, folderItem, folderid, foldername, parentID

msg = ""

Set xmlDOM = CreateObject("MSXML2.DOMDocument")
xmlDOM.LoadXml "<?xml version=""1.0"" encoding=""utf-8""?> <index> <exportdate>2014-01-01</exportdate> <folders> <folder> <id>384</id> <name>Grandmother</name> <documents/> <folders> <folder> <id>404</id> <name>Parent1</name> <documents/> <folders> <folder> <id>405</id> <name>Child1.1</name> <documents> <document> <id>1</id> <version>1.0</version> <title>Directiebeoordeling O&amp;G</title> <extension>.docx</extension> <summary/> <iconurl/> <viewerurl/> </document> <document> <id>2</id> <version>1.0</version> <title>doc2</title> <extension>.docx</extension> <summary/> <iconurl/> <viewerurl/> </document> <document> <id>3</id> <version>1.0</version> <title>doc3</title> <extension>.docx</extension> <summary/> <iconurl/> <viewerurl/> </document> </documents> <folders/> </folder> <folder> <id>407</id> <name>Child1.2</name> <documents> <document> <id>4</id> <version>1.0</version> <title>doc4</title> <extension>.docx</extension> <summary/> <iconurl/> <viewerurl/> </document> </documents> <folders/> </folder> <folder> <id>408</id> <name>Child1.3</name> <documents/> <folders/> </folder> </folders> </folder> <folder> <id>389</id> <name>Parent2</name> <documents/> <folders> <folder> <id>385</id> <name>Child2.1</name> <documents/> <folders/> </folder> </folders> </folder> </folders> </folder> </folders> </index>"

Set folder = XMLDom.SelectNodes("//folders/folder")

For Each folderItem In folder
	folderid =folderItem.SelectSingleNode("id").text
	foldername=folderItem.SelectSingleNode("name").text

	If folderItem.parentNode.parentNode.nodeName = "folder" Then
		parentID = folderItem.parentNode.parentNode.selectSingleNode("id").Text
	Else
		parentID = 0 ' top level
	End If

	msg = msg & "INSERT INTO ... (parentID, folderID, folderName) VALUES (" & parentID & ", " & folderid & ", '" & Replace(foldername, "'", "''") & "')" & vbcrlf
Next
Set xmlDOM = Nothing

msgbox msg

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SteynskAuthor Commented:
Again Robert. Thank you very much for excellent your help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.