9 Replies Latest reply on Dec 21, 2009 10:27 AM by Francisc

    How to read xml data?

    Charu Shukla

      I need urgent help with this code to read xml nodes from an xml file.



      This is the HttpService


      <mx:HTTPService id="appraisalData"




                  private var _appData:XMLList=new XMLList();


                  private function HandleDataResult(event:ResultEvent):void



      I want to extract nodes from this XMLList and fill my components



      <components:HeaderSection width="100%"  headerData="{XML(_appData[0])}"/>



      Here's the XML file sample:


      <?xml version="1.0"?>
      <EMPLOYEE>Tom Smith</EMPLOYEE>
      <LEADER>Bob string hello Jr</LEADER>
      <APPRAISAL_TYPE>2010 Individual Contributor</APPRAISAL_TYPE>
      <ORGUNIT>Payroll Test Org.2</ORGUNIT>
      <EE_SUBGROUP>Full Time Non-Exempt</EE_SUBGROUP>

        • 1. Re: How to read xml data?
          Francisc Level 3

          If you can wait until I get home, I'll write the answer... 8h or so until then.

          Otherwise, use the Debug view to see if you are reading the XML and if so, how it gets there.

          If that won't help, look here: http://buildinternet.com/2008/12/xml-basics-with-flex-3/

          If you follow those steps you will have your XML imported in no time.


          Good luck!

          1 person found this helpful
          • 2. Re: How to read xml data?
            Charu Shukla Level 1

            Thanks for the reply, hope you get home soon and help me out.

            • 3. Re: How to read xml data?
              pauland Level 4

              Charu, you'll learn more by trying yourself first. There's loads of articles out there on google that will get you started.


              Better to have a go then get help with your attempt than have a solution on a plate.



              • 4. Re: How to read xml data?
                Charu Shukla Level 1

                Well i have been trying it out for few days now, am not able to find the right solution.

                • 5. Re: How to read xml data?
                  Matt Le Fevre Level 4

                  reading XML is really a bread and butter matter when it comes to Flex,


                  just watch where your Tags begin and End, and you really shouldn't come into any problems.


                  there are loadssssssssssssss of examples out there, just find a working one, look at the source code and you'll be sorted

                  • 6. Re: How to read xml data?

                    Charu, try this


                    [Bindable] private var testXML:XML;


                    protected function init():void {

                        var serviceObj:HTTPService = new HTTPService();

                        serviceObj.resultFormat = 'e4x';

                        serviceObj.method = 'GET';

                        serviceObj.useProxy = false;

                        serviceObj.addEventListener(ResultEvent.RESULT, processResult);

                        serviceObj.url = 'wassets/appraisal.xml';




                    // The result processing function

                    protected function processResult(response:ResultEvent):void {

                        // make sure the response is cast as the correct data type

                        testXML = response.result as XML;



                    Now u can use the testXML in your Datagrid.

                    1 person found this helpful
                    • 7. Re: How to read xml data?
                      pauland Level 4

                      The XML in your example is not correctly formed - start there first.

                      • 8. Re: How to read xml data?
                        Francisc Level 3

                        Honeeeey, I'm hooome! So... here's the code:






                        import mx.controls.Alert;

                        import mx.rpc.events.FaultEvent;

                        import mx.rpc.events.ResultEvent;

                        import mx.collections.ArrayCollection;


                        private var myRetrivedData:ArrayCollection;


                        private function getXMLData():void




                        private function httpFaultHandler(event:FaultEvent):void


                             Alert.show("Cannot load XML file.","Error");


                        private function httpResultHandler(event:ResultEvent):void







                        <mx:HTTPService id="httpService" url="someXMLFile.xml"

                             fault="httpFaultHandler(event)" result="httpResultHandler(event)"/>


                        <mx:DataGrid id="myDataGrid" dataProvider="{myRetrivedData}"/>

                        • 9. Re: How to read xml data?
                          Francisc Level 3

                          Your XML is rather odd as well.

                          You should format it simmilar to this for example:




                                    <name>Wayne Rooney</name>






                                    <name>Ryan Giggs</name>