Recursively creating a DOM Tree

Discussion in 'XML' started by Neil, Jan 23, 2004.

  1. Neil

    Neil Guest

    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
    Neil, Jan 23, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark
    Replies:
    9
    Views:
    5,092
  2. =?Utf-8?B?RGFuIE5hc2g=?=

    adding subnodes to a tree recursively

    =?Utf-8?B?RGFuIE5hc2g=?=, Oct 16, 2004, in forum: ASP .Net
    Replies:
    10
    Views:
    659
    =?Utf-8?B?UGF0cmljay5PLklnZQ==?=
    Oct 18, 2004
  3. Joris Gillis
    Replies:
    2
    Views:
    1,521
    Joris Gillis
    Jun 16, 2006
  4. Stub

    B tree, B+ tree and B* tree

    Stub, Nov 12, 2003, in forum: C Programming
    Replies:
    3
    Views:
    10,090
  5. Mathematisch
    Replies:
    8
    Views:
    113
Loading...

Share This Page