dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: display a number for all siblings

  1. #1
    Senior Member
    Join Date
    May 2003
    Posts
    160

    display a number for all siblings

    Hey I have class that has 3 siblings plus the firstChild ...

    PHP Code:
    <classes>

    <class 
    state="NJ">
    <
    text desc="NJ Performance"></text>
    <
    text desc="115 Route 46"></text>
    <
    text desc="201-GO-FAST1"></text>
    <
    text desc="www.njperformance.com"></text>
    </class>

    </
    classes
    How can I count all the siblings included in one class ...

    like this would display #4 ... thanks

    -s

  2. #2
    Retired Mod aversion's Avatar
    Join Date
    Jun 2000
    Location
    insomnia
    Posts
    7,917
    say your XML is called "classXML"

    code:
    classXML.firstChild.childNodes(0).childNodes.lengt  h



    will return the number of text items inside the first class.

    the childNodes property is similar to an array of childNodes for that node, so

    classXML is the whole document
    classXML.firstChild is the whole document inside the first tag (not including any declarations)
    classXML.firstChild.childNodes[0] is the number of siblings of the first child, so in this case it's just 1, which, using the array style reference, is childNodes[0].
    classXML.firstChild.childNodes[0].childNodes similarly, this refers to the array of child nodes of the previous node and you can apply a few array style properties, such as length, to make life easier.

    as a further example, to refer to your second <text> node inside the class tag you would use;

    code:
    classXML.firstChild.childNodes(0).childNodes[1]



    Last edited by aversion; 09-17-2003 at 09:08 AM.

  3. #3
    Senior Member
    Join Date
    May 2003
    Posts
    160
    Thanks man, makes sense to me now ...

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