1 Reply Latest reply on May 20, 2009 8:48 AM by Gregory Lafrance

    Problem with XML and HTTPService

    thedex1 Level 1

      Hi, I have little but strange problem. I have an xml file that I am reading it via HTTPService. The problem is that if xml file contains one child node, the HTTPService says, "A term is undefined and has no properties...." but if I add just one more, it works perfect.

       

      Here is my xml file:

      <Items>
          <item>
              <name>item1</name>
          </item>   
      </Items>

       

      and Here is my Application:

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"creationComplete="service.send()">
      <mx:Script>
          <![CDATA[
              import mx.rpc.events.ResultEvent;
              import mx.controls.Alert;
              public function testHandler(event:ResultEvent):void
              {           
                  Alert.show(event.result.Items.item.length.toString());
              }
          ]]>
      </mx:Script>
          <mx:HTTPService url="test.xml" id="service" result="testHandler(event);" />
             
      </mx:Application>

       

      Not sure why it is behaving this way.... any idea would be really really appreciated.

       

      Thanks a lot ...

       

      ...

      .:.WAHAB

        • 1. Re: Problem with XML and HTTPService
          Gregory Lafrance Level 6

          This works. Set the resultFormat to e4x and change the way you access the data.

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="service.send();">
          <mx:Script>
              <![CDATA[
                  import mx.rpc.events.ResultEvent;
                  import mx.controls.Alert;
                  public function testHandler(event:ResultEvent):void
                  {           
                      Alert.show(event.result.item.name.toString());
                  }
              ]]>
          </mx:Script>
              <mx:HTTPService url="test.xml" id="service" result="testHandler(event);"
                resultFormat="e4x" />
                 
          </mx:Application>