2 Replies Latest reply on Apr 16, 2007 1:53 PM by cluebcke

    Help with E4X

    ojk007 Level 1
      So i have an xml file like so
      ------
      <musicdb>
      <genres>
      <genre value="1" number="0"/>
      </genres>
      <artists/>
      </musicdb>
      ----

      the genres is the block im looking at atm.
      Firstly I have a list of songs, which are parsed through one by one, they have their ID3 tags read.
      so i want to "check if genre entry is present, if not add it"

      basically i wanna check to see if the current songs genre is equal to any of the genres.genre@value

        • 1. Help with E4X
          Santanu Karar Level 1
          .
          • 2. Re: Help with E4X
            cluebcke Level 1
            So this is the problem you're trying to solve, right?

            quote:

            basically i wanna check to see if the current songs genre is equal to any of the genres.genre@value


            Assuming that:

            1. You have your xml in an XMLList
            2. The XMLList is referenced by a variable that's also named "musicdb" (it's a good practice, imo, to name your XML objects the same as the root element--reduces confusion)
            3. The current song's genre is in some String or Number called "currentGenre"

            Then the expression

            var result : XMLList = musicdb.genres.genre.(@value == currentGenre)

            Will return you an XMLList containing all <genre>s whose value attribute is equal to currentGenre. The result.length() will tell you the number of elements in the new XMLList; if it's 0, there was no match.

            Not exactly sure if that's what you needed, but I hope it's a start.

            - Chris