4 Replies Latest reply on Nov 23, 2009 7:04 AM by Sorcery

    e4x filter

    Sorcery

      Hi

       

      I try to filter a xml file whit e4x function


        HttpServie whit  e4x format

      <mx:HTTPService id="catXml" url="data/data.xml" resultFormat="e4x"
      result="httpSResult_Handler(event)"
      />

        Actionscript

      public var itemsTree:XMLList ;
      public function httpSResult_Handler(e:Event):void{
      itemsTree= catXml.lastResult.operatore;

      }

       

      If i try to read normal xml it's ok, but if i try to filter it...

      public function httpSResult_Handler(e:Event):void{
      itemsTree=catXml.lastResult.operatore.(settore == "3").toString();
      }

      Error : "operatore" not defined??

       

      Thank's for help.

      xml file
      <root>
      <operatore>
      <nome>nome</nome>
      <cognome>cognome</cognome>
      <num_matricola>43</num_matricola>
      <settore>3</idtbl_operatore_settore>
      <settore2>0</idtbl_operatore_settore2>
      </operatore>
      <operatore>
      <nome>nome</nome>
      <cognome>cognome</cognome>
      <num_matricola>43</num_matricola>
      <settore>3</idtbl_operatore_settore>
      <settore2>0</idtbl_operatore_settore2>
      </operatore>
      ....
      </root>

        • 1. Re: e4x filter
          paul.williams Level 4

          The filter expression works fine for me in a standalone app (although your xml is invalid). Can you post the full error?

          • 2. Re: e4x filter
            chris.huston.t10

            Your XML structure for the settore tags was not correct. You need to have a closing tag. The following works for me:

             

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" initialize="init()">
                <mx:Script>
                    <![CDATA[
                        private var catXml:XML = <root>
            <operatore>
            <nome>nome</nome>
            <cognome>cognome</cognome>
            <num_matricola>43</num_matricola>
            <settore>3</settore>
            <settore2>0</settore2>
            </operatore>
            <operatore>
            <nome>nome</nome>
            <cognome>cognome</cognome>
            <num_matricola>43</num_matricola>
            <settore>4</settore>
            <settore2>0</settore2>
            </operatore>
            </root>;
                       
                        private function init():void {
                            trace(catXml.operatore.(settore=="3").toString());
                        }
                    ]]>
                </mx:Script>
            </mx:Application>

             

            I would also suggest using the ResultEvent rather than the lastResult property like this:

             

            public function httpSResult_Handler(e:ResultEvent):void{
            itemsTree=e.result.operatore.(settore == "3").toString();
            }

             

            Chris

            • 3. Re: e4x filter
              RK...

              Hi, In your xml, settore and  settore2 don't have proper closing tags. Please try this

               

              <root>

              <operatore>

              <nome>nome</nome>

              <cognome>cognome</cognome>

              <num_matricola>43</num_matricola>

              <settore>3</settore>

              <settore2>0</settore2>

              </operatore>

              <operatore>

              <nome>nome</nome>

              <cognome>cognome</cognome>

              <num_matricola>43</num_matricola>

              <settore>2</settore>

              <settore2>0</settore2>

              </operatore>

              </root>

               

               

              private function httpSResult_Handler(event: ResultEvent): void {

              var result: XMLList = (event.result as XML).*;

              var filterResult: XMLList = result.(settore == 3);

              Alert.show(filterResult.toXMLString());

              }

              • 4. Re: e4x filter
                Sorcery Level 1

                Hi

                 

                thank's for Help.