如何从flex中读取XML文件中的数据?
答案 0 :(得分:2)
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());
}
答案 1 :(得分: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>
答案 2 :(得分:1)
您可以使用URLRequest和URLLoader加载xml文件,然后处理它们。请查看以下示例flex - load xml using URLLoader and extract data
答案 3 :(得分:0)