7 Replies Latest reply on Apr 7, 2008 10:26 AM by ntsiii

    E4X problem

    MayLam18
      Hi everyone,

      I am having problem with e4x. If possible, please help me. Thanks.

      Below XML is displayed by the trace statement #1.

      <GetAndCheckLogInUserResponse xmlns=" http://FaciNet.com/">
      <GetAndCheckLogInUserResult>
      <LogInUser>
      <SouID>2</SouID>
      <LogInUserID>5</LogInUserID>
      <LogInUserName>jimmylam</LogInUserName>
      <DialectID>1</DialectID>
      <CreatedByUserID>1</CreatedByUserID>
      <UpdatedByUserID>1</UpdatedByUserID>
      </LogInUser>
      </GetAndCheckLogInUserResult>
      </GetAndCheckLogInUserResponse>

      How come trace statement #2 does not display 2. How can I display the 2 (SouID)? Please help. Thanks.

      May

      import mx.rpc.events.ResultEvent;
      namespace FaciNS = " http://FaciNet.com/";
      import mx.utils.ObjectUtil;

      public var __xmlResult:XML;
      public function onResult(e:ResultEvent):void {
      __xmlResult = new XML(e.result);

      trace(__xmlResult); // trace statement #1

      trace(__xmlResult.GetAndCheckLogInUserResult.LogInUser.SouID); // trace statement #2

      }
        • 1. E4X problem
          flexsea Level 1
          As a workaroung, you might wish skip all intermediate elements and just retrieve the respective node's value [use two dots]:

          >>>
          trace(__xmlResult..SouID); // trace statement #2
          <<<


          • 2. E4X problem
            cxf02 Level 1
            Wrap your xml like this...
            <x>
            <GetAndCheckLogInUserResponse xmlns=" http://FaciNet.com/">
            <GetAndCheckLogInUserResult>
            <LogInUser>
            <SouID>2</SouID>
            <LogInUserID>5</LogInUserID>
            <LogInUserName>jimmylam</LogInUserName>
            <DialectID>1</DialectID>
            <CreatedByUserID>1</CreatedByUserID>
            <UpdatedByUserID>1</UpdatedByUserID>
            </LogInUser>
            </GetAndCheckLogInUserResult>
            </GetAndCheckLogInUserResponse>
            </x>

            You need a root node.

            Also, see this thread for some useful code using e4x:
            http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?catid=585&threadid=1348661
            • 3. Re: E4X problem
              flexsea Level 1
              You might wish to 'import' the namespace:

              >>>>
              import mx.rpc.events.ResultEvent;
              import mx.utils.ObjectUtil;

              public function doTestt():void {

              var xa:XML = <GetAndCheckLogInUserResponse xmlns:FA=" http://FaciNet.com/">
              <GetAndCheckLogInUserResult>
              <LogInUser>
              <SouID>23</SouID>
              <LogInUserID>5</LogInUserID>
              <LogInUserName>jimmylam</LogInUserName>
              <DialectID>1</DialectID>
              <CreatedByUserID>1</CreatedByUserID>
              <UpdatedByUserID>1</UpdatedByUserID>
              </LogInUser>
              </GetAndCheckLogInUserResult>
              </GetAndCheckLogInUserResponse>;

              trace(xa); // trace statement #1

              var FANamespace:Namespace = new Namespace("w", " http://FaciNet.com/");
              xa.addNamespace(FANamespace);

              trace( 'XX#' + xa.GetAndCheckLogInUserResult.LogInUser.SouID + '#' ); // trace statement #2
              }
              <<<
              • 4. Re: E4X problem
                MayLam18 Level 1
                quote:

                Originally posted by: flexsea
                As a workaroung, you might wish skip all intermediate elements and just retrieve the respective node's value [use two dots]:

                >>>
                trace(__xmlResult..SouID); // trace statement #2
                <<<





                Hi,

                Thanks for your help! But your code returns nothing. Please help. Thanks.

                May
                • 5. Re: E4X problem
                  MayLam18 Level 1
                  quote:

                  Originally posted by: flexsea
                  You might wish to 'import' the namespace:

                  >>>>
                  import mx.rpc.events.ResultEvent;
                  import mx.utils.ObjectUtil;

                  public function doTestt():void {

                  var xa:XML = <GetAndCheckLogInUserResponse xmlns:FA=" http://FaciNet.com/">
                  <GetAndCheckLogInUserResult>
                  <LogInUser>
                  <SouID>23</SouID>
                  <LogInUserID>5</LogInUserID>
                  <LogInUserName>jimmylam</LogInUserName>
                  <DialectID>1</DialectID>
                  <CreatedByUserID>1</CreatedByUserID>
                  <UpdatedByUserID>1</UpdatedByUserID>
                  </LogInUser>
                  </GetAndCheckLogInUserResult>
                  </GetAndCheckLogInUserResponse>;

                  trace(xa); // trace statement #1

                  var FANamespace:Namespace = new Namespace("w", " http://FaciNet.com/");
                  xa.addNamespace(FANamespace);

                  trace( 'XX#' + xa.GetAndCheckLogInUserResult.LogInUser.SouID + '#' ); // trace statement #2
                  }
                  <<<


                  Hi,

                  Thanks for your help! I have just tried your code. And it returns XX##. I want 2. Please help. Thanks.

                  May
                  • 6. Re: E4X problem
                    MayLam18 Level 1
                    Note: The XML below is come from the Web Service. And not hard code.

                    <GetAndCheckLogInUserResponse xmlns=" http://FaciNet.com/">
                    <GetAndCheckLogInUserResult>
                    <LogInUser>
                    <SouID>2</SouID>
                    <LogInUserID>5</LogInUserID>
                    <LogInUserName>jimmylam</LogInUserName>
                    <DialectID>1</DialectID>
                    <CreatedByUserID>1</CreatedByUserID>
                    <UpdatedByUserID>1</UpdatedByUserID>
                    </LogInUser>
                    </GetAndCheckLogInUserResult>
                    </GetAndCheckLogInUserResponse>
                    • 7. Re: E4X problem
                      ntsiii Level 3
                      Always use toXMLString() to display XML.

                      Try this see if you see you xml.

                      Tracy