3 Replies Latest reply on Mar 22, 2007 6:35 AM by Painball

    childNodes

    Painball
      Ok a fast one :)

      I need to get data from xml.....this is working out fine
      --------------------------------------------------------------------------------
      XLM looks like this:
      <?xml version="1.0" encoding="UTF-8"?>
      <hej_a_b>
      <letter l_name = "a">
      <item i_name="Absolut" i_video="absolut.flv"/>
      <item i_name="Acceptera" i_video="acceptera.flv"/>
      <item i_name="Adress" i_video="adress.flv"/>
      <item i_name="Advent" i_video="advent.flv"/>
      <item i_name="Affär" i_video="affär.flv"/>
      </letter>


      <letter l_name = "b">
      <item i_name="Bada" i_video="bada.flv"/>
      <item i_name="Badboll" i_video="badboll.flv"/>
      <item i_name="Badbyxa" i_video="badbyxa.flv"/>
      </letter>
      </hej_a_b>
      ------------------------------------------------------------------

      to get infro from
      <letter l_name = "a">
      <item i_name="Absolut" i_video="absolut.flv"/>

      i use this : var nodes = this.firstChild.firstChild.childNodes ;


      but how do i get info from this one :
      <letter l_name = "b">
      <item i_name="Bada" i_video="bada.flv"/>

      ive tried many possible ways but it wont just work.
      do i have to use XML elements in some way ?


      /j
        • 1. Re: childNodes
          SymTsb Level 2
          There is a tutorial on gotoandlearn.com for a Flash mp3 player. Watch the tutorials as they will show you exactly how to do this.
          • 2. Re: childNodes
            Level 7
            >> to get infro from
            >> <letter l_name = "a">
            >> <item i_name="Absolut" i_video="absolut.flv"/>
            >>
            >> i use this : var nodes = this.firstChild.firstChild.childNodes ;

            Okay.

            >> but how do i get info from this one :
            >> <letter l_name = "b">
            >> <item i_name="Bada" i_video="bada.flv"/>

            Well, the childNodes property gives you an array. In your first
            example, this.firstChild.firstChild refers to the <letter> node, and the
            final childNodes property then refers to the <letter> node's children. In
            your code sample the <letter l_name="a"> node has five children, so you
            could access them like this ...

            this.firstChild.firstChild.childNodes[0];
            this.firstChild.firstChild.childNodes[1];
            this.firstChild.firstChild.childNodes[2];
            this.firstChild.firstChild.childNodes[3];
            this.firstChild.firstChild.childNodes[4];

            Makes sense, right? Well, your <letter> node is *also* a child, which
            means it also falls within the childNodes property of its parent. It's just
            that firstChild happens to be the l_name="a" one. This reference ...

            this.firstChild.firstChild.childNodes[0];

            ... is the same as saying this ...

            this.firstChild.childNodes[0].childNodes[0];

            ... so to get to the l_name="b" ones, you could do this ...

            this.firstChild.childNodes[1].childNodes[0];
            this.firstChild.childNodes[1].childNodes[1];
            this.firstChild.childNodes[1].childNodes[2];
            // etc.


            David Stiller
            Adobe Community Expert
            Dev blog, http://www.quip.net/blog/
            "Luck is the residue of good design."


            • 3. Re: childNodes
              Painball Level 1
              Stiller, you are my hero.

              Thank you