dcsimg
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [Resolved] [Resolved] [Resolved] [Resolved] [Resolved] counting nodes

  1. #1
    Senior Member
    Join Date
    Mar 2002
    Posts
    121
    Is their anyway to find the number of childnodes a particular node has?

  2. #2
    Member
    Join Date
    Oct 2001
    Location
    Italy
    Posts
    51
    Something like:
    myXML.firstChild.childNodes.length
    should suit you fine.
    Bye
    Carla

  3. #3
    Senior Member
    Join Date
    Mar 2003
    Posts
    111
    is there a way to count the number of nodes (not child nodes) an XML document has?

  4. #4
    Senior Member tupps's Avatar
    Join Date
    Jan 2001
    Location
    Melbourne
    Posts
    2,035
    To count the number of nodes use a recursive function:

    function countNodes(nextNode)
    {
    for (var i = 0; i < nextNode.childNodes.length; i++)
    {
    _global.nodeCounter++;
    countNodes(nextNode.childNodes[i])
    }

    }

    Basically this will 'walk' through the xml tree counting every node. You might want to turn off whitespace or check for text nodes which will increase the node count.

    Thanks

    Luke
    Flash-XML FAQ
    http://www.tupps.com/flash/faq/

  5. #5
    Member
    Join Date
    Jul 2000
    Posts
    50
    Can someone please elaborate on the node counter and how I would setup everything (defining xml object) to make it run?

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center