Recursively creating a DOM Tree

N

Neil

Hi,

I'm new to all this so any help would be appreciated.

I'm trying to build a DOM Tree by retrieving info from the database
and storing these objects as elements.

I have a structure a bit like windows explorer with folders within
folder within folders.... e.g.

<folder id="1" parent="0">
<title>Folder 1</title>
<folder id="2" parent="1">
<title>Sub Folder 1</title>
</folder>
</folder>

Now I've written a recursive function that calls until the last folder
is reached. It looks like this:

--------------------------------------------------------------------------------
<snip>

function traverseFolderNodes(folderId, parentFolder)
sql = "SELECT a.id, a.folderName, b.parentId FROM tblFolders a INNER
JOIN tblFolders_To_Folders b " & _
"ON b.childId = a.id WHERE b.parentId = " & folderId

set rsFolder = SQLString(sql)
if not rsFolder.EOF then

***PROBLEM ON LINE BELOW***

xmlGenerator.createElement "entity", folderElement
xmlGenerator.createTextElement "title", titleElement,
rsFolder("folderName")
xmlGenerator.createTextElement "image", imageElement,
"img/book.gif"
xmlGenerator.createTextElement "imageopen", imageOpenElement,
"img/bookopen.gif"


xmlGenerator.addChild parentFolder, folderElement
xmlGenerator.addAttribute folderElement, "id", rsFolder("id")
xmlGenerator.addAttribute folderElement, "parent",
rsFolder("parentId")
xmlGenerator.addChild folderElement, titleElement
xmlGenerator.addChild folderElement, imageElement
xmlGenerator.addChild folderElement, imageOpenElement


do while not rsFolder.EOF and folderId <> ""

traverseFolderNodes rsFolder("id"), folderElement
rsFolder.moveNext()
loop
end if
end function

public sub createElement(elementName, byRef element)
Set element = objDom.createElement(elementName)
end sub

</snip>
--------------------------------------------------------------------------------

The error message I am getting is:

"Inserting a Node or its ancestor under itself is not allowed."

Any words of wisdom would be appreciated
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,231
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top