我在flex中创建了一个数组集合,我有一个XML文件。 现在我想将该XML文件称为arraycollection,所以请给我一些相同的想法。 我怎么能实现这个???
提前致谢---
答案 0 :(得分:0)
首先从XML中提取所需节点的XMLList
。然后按以下方式使用ArrayUtil.toArray()
:
var myCollection:ArrayCollection = new ArrayCollection(ArrayUtil.toArray(myXMLList));
答案 1 :(得分:0)
<!-- Application -->
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
private var arrColl:ArrayCollection;
protected function creationCompleteHandler(event:FlexEvent):void
{
arrColl = new ArrayCollection(books.book);
}
]]>
</fx:Script>
<fx:Declarations>
<fx:Model id="books" source="books.xml"/>
</fx:Declarations>
<!-- books.xml -->
<?xml version="1.0"?>
<books>
<book>
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
</book>
<book>
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
</book>
<books>