4 Replies Latest reply on Jul 25, 2008 2:02 PM by Developer504

    Filtering e4x to find a specific record

      I'm trying to start over again. I'm a bit confused over the terminology.

      Assuming I have this XML imported into an XMLList:

      <gauge label="CM" value="148.17" />
      <gauge label="DE" value="103.31" />
      <gauge label="EN" value="99.46" />

      I want to assign each record value in this XML to a different variable, at the time my WS call is triggered, so I want to do it within a script. So far I have been trying to put something within my HTTPService handler.

      I have tried many things today, so far for no luck.

      Can anyone help me here?

        • 1. Re: Filtering e4x to find a specific record
          ntsiii Level 3
          Ok, If you have already declared your variables in instance scope, then you can just do:
          • 2. Filtering e4x to find a specific record
            Developer504 Level 1
            Yes thank you so much that is exactly what i was trying to figure out.

            So if you will bear with me, so I understand:

            You need to declare a local variable within your function to take the result, then you use the e4x parenthetical with the command "attribute" to pick out the specific value. This seems to be what I was missing.

            I had already assigned the value to a bindable public variable and was trying to parse that but was missing this 'attribute' tag I guess.

            Can you use a public variable the same way?
            • 3. Re: Filtering e4x to find a specific record
              ntsiii Level 3
              Yes to the public var, in fact that is really more normal.

              The expression inside the parentheses evaluates to a Boolean. It can literally be anything that does, including calling out to another function. I do this when I have a very complex criteria.

              Both attribute("attributeName") and @attributeName are used to access xml attributes (...label="CM"...). Note I used both in my example. The difference is that when used in a filter expression, @attributeName will error if ANY node in the xml does not have an "attributeName" attribute declared. attribute() does not error. So I always use attribute() in filter expressions.

              If you go back and look through the docs Amy pointed out you will see this all discussed, though perhaps not as concisely.

              • 4. Re: Filtering e4x to find a specific record
                Developer504 Level 1
                Thanks, when it comes to those documents I guess I need a filter on my search to understand how to filter.

                Where I seem to have trouble is in the finer points of the syntax, not having enough familiarity I can miss something like the subtle nuance between using an @ vs. a ("xxx") due to the potential issue of an error-out. The double equal signs thing was a major "gotcha" for me for a long time because I'd seen them used both ways (either "=" or "==") in different parts of the code.

                I'm only now beginning to 'see' the different grammar of mxml, actionscript and things like e4x.

                I really appreciate your patient help.