3 Replies Latest reply on May 10, 2012 3:56 AM by _spoboyle

    xml question

    WuLink

      var x:XML = <datas>

                          <data id="1" name="a" txt="aa" />

                          <data id="2" name="b" txt="bb" />

                          <data id="3" name="c" txt="cc" />

                </datas>;

       

       

      var id:int = 1;

      var name:String = "b";

       

       

      trace(x.data.(@id == id).@txt);

      trace(x.data.(@name == name).@txt);

       

      sdk3.5:

      aa

      bb

       

      sdk3.6:

      aa

      bb

       

      sdk4.5:

      aa

      //no output

       

      sdk4.6:

      aa

      //no output

       

       

      any one help me? bug or else?

        • 1. Re: xml question
          _spoboyle Level 4

          can't explain why yet but it's do to with the name of the local variable called name

           

          in case you haven't seen this yourself the following fixes the issue

           

          var x:XML = <datas>

                              <data id="1" name="a" txt="aa" />

                              <data id="2" name="b" txt="bb" />

                              <data id="3" name="c" txt="cc" />

                    </datas>;

           

           

          var id:int = 1;

          var name_:String = "b";

           

           

          trace(x.data.(@id == id).@txt);

          trace(x.data.(@name == name_).@txt);

          • 2. Re: xml question
            _spoboyle Level 4

            not sure what this means yet but

             

                                          var x:XML =   <datas>

                                                              <data id="1" name="a" txt="aa" />

                                                              <data id="2" name="b" txt="bb" />

                                                              <data id="3" name="c" txt="cc" />

                                                    </datas>;

             

                                          var id:int = 1;

                                          var name:String = "b";

             

                                          trace(x.data.(@id == id).@txt);

                                          trace(x.data.(@name.indexOf(name)>-1).@txt);

             

            outputs

            aa

            aabbcc

            • 3. Re: xml question
              _spoboyle Level 4

              ok i think this means that when

               

              trace(x.data.(@name == name).@txt);

               

              comes to evaluate name, name = "" (the empty string)

               

              this looks like a bug to me, possible some sort of scoping issue

               

              the following also give you the output you want confirming that name is being evaluated to the empty string

               

              var x:XML =   <datas>

                                                                <data id="1" name="a" txt="aa" />

                                                                <data id="2" name="b" txt="bb" />

                                                                <data id="3" name="c" txt="cc" />

                                                      </datas>;

               

                                            var id:int = 1;

                                            var name:String = "b";

               

                                            trace(x.data.(@id == id).@txt);

                                            trace(x.data.(@name == (name+"b")).@txt);

              1 person found this helpful