1 Reply Latest reply on Jul 15, 2010 10:58 PM by BhaskerChari

    'Simple' xml parsing

    boneitis

      Alright, so i feel like dumb *** posting this, however I can't get passed it..

       

      I have the following xml block

       

      <?xml version="1.0" encoding="UTF-8"?>
      <List>
      <questions><![CDATA[feline,canine,rodent]]></questions>
      <answers><![CDATA[cats,dogs,mice]]></answers>
      </List>

       

      I need to parse out the nodes questions and answers.

       

      What I've tried:

      public function init():void{
          var loader:URLLoader = new URLLoader();
          loader.addEventListener( Event.COMPLETE, success);
          loader.load( new URLRequest( "someXml.xml" ) );
      }

       

      private function success( _event:Event ):void{
          var xml:XML = new XML( (_event.target as URLLoader).data );
          trace(xml.list.questions)
      }

       

      Outcome

      blank trace statement.  In the debugger in flex, I see the proper information on 'xml' and 'xml.list' but when it hits 'xml.list.questions'  it is blank.

       

      I've been banging my head against this for a fwe hours, and there is no reason for it. I've used E4X many times, however never had the CDATA section in any xml.

       

      Please have mercy on me

      -Andrew

        • 1. Re: 'Simple' xml parsing
          BhaskerChari Level 4

          Hi Andrew,

           

          You need to have the trace statement as  trace(xml.questions); but not  trace(xml.list.questions)....

           

          Because now xml corresponds to the root tag of xml which is list..So you need to directly use xml.questions in trace statement.'

           

          If this post answers your question or helps, please kindly mark it as such.


          Thanks,

          Bhasker Chari