0

How to read data from XML file in flex?

4 Answers 4

2

Use URLLoader

var ldr:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("file.xml");
ldr.addEventListener(Event.COMPLETE, onLoad);
ldr.load(request);

private function onLoad(e:Event):void
{
  var ldr:URLLoader = URLLoader(e.target);
  trace(ldr.data);//traces the string content of file
  var myxml:XML = new XML(ldr.data);
  trace(myxml.toXMLString());
}
Sign up to request clarification or add additional context in comments.

Comments

1

You can load the xml files using the URLRequest and URLLoader and then process them. Check following example, flex - load xml using URLLoader and extract data

Comments

1
<?xml version="1.0" encoding="utf-8"?>

<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="bookdat.send()">

mx:HTTPService id="bookdat" url="books.xml" resultFormat="e4x" 

result="bookhandler(event)"/>




<mx:DataGrid id="dg" dataProvider="{booklist}" width="500"/>

<mx:Script>
    <![CDATA[

        import mx.rpc.events.ResultEvent;

       [Bindable]
        var booklist:XMLList=new XMLList();
        public function bookhandler(e:ResultEvent)
        {
      booklist=e.result.stock.(category=="Fiction").name;
     // booklist=e.result.stock
        }
    ]]>
</mx:Script>
</mx:WindowedApplication>

Comments

0

Check out the HTTPService example in Tour de Flex.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.