将xml转换为对象

时间:2013-07-15 09:55:55

标签: xml actionscript-3 actionscript

我是关于actionscript的那个主题的初学者,但我有一个像下面这样的大型xml响应,我不知道如何将它转换为类,那里有很多字段,我如何构造它们正确吗?

<GCPResponse userLocale=”de_AT_7_1”>
<Messages>
<PopUpMessages>
<Message no=”1” type=”game” name=”DONATION” key="detailKeyIfNecessary">
 ahhhdhhdhdhd
</Message>
</PopUpMessages>
<TickerMessages>
<Message no=”1” type=”game” name=”TTJP” key="detailKeyIfNecessary">
  fdfdfd
</Message>
<Message no=”2” type=”game” name=”LDJP”>
 fffff
</Message>
</TickerMessages>
</Messages>
<Response currency=”EUR”>
<BalanceCash>10000</BalanceCash>
<BalanceDonation>10000</BalanceDonation>
<DrawClosingTime>2013-04-12T23:20:50+01:00</DrawClosingTime>
<DrawOpeningTime>2013-04-10T12:00:00+01:00</DrawOpeningTime>
<Default maxDraws=”4” draws=”1” picks=”12” jokerPicks=”1”/>
<PickPrice gameName=”ttt” draw=”123” price=”60”/>

    </Response>
</GCPResponse>

1 个答案:

答案 0 :(得分:0)

使用URLLoader加载外部XML文件,即:

import flash.net.URLLoader;

...

private var _loader:URLLoader = new URLLoader();
private var _xml:XML;
private var _XMLselection:XMLList;

...

_loader.load(new URLRequest("assets/commissionercontent.xml"));
_loader.addEventListener(Event.COMPLETE, xmlLoaded);
_loader.addEventListener(IOErrorEvent.IO_ERROR, xmlError);

private function xmlError(p_event:Event):void {
    trace("XML error - maybe do something graphical here?");
}

private function xmlLoaded(p_event:Event):void {
    _xml=new XML(p_event.target.data);
}

将XML作为Flash XML对象后,您可以进行选择,例如:

_XMLselection = _xml.GCPResponse.Fixtures;

检查adobe live docs ... http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/XML.html