I have an XML file I'm reading in where a branch of the tree looks like this:
<data id="Shallow" label="Show Shallow Imagery (1 m)">
<layer name="Bathymetry" url="OtherImagery" type="Dynamic" legendurl="">
<visiblelayers>1</visiblelayers>
<visiblelayers>4</visiblelayers>
</layer>
<layer name="Backscatter" url="OtherImagery" type="Dynamic" legendurl="">
<visiblelayers>2</visiblelayers>
</layer>
<layer name="PCA" url="BUIS_Imagery" type="Dynamic" legendurl="">
<visiblelayers>3</visiblelayers>
<visiblelayers>4</visiblelayers>
</laye开发者_如何学Gor>
</data>
The user selects the layer using a radiobutton and in the click event, I pass layer.(@name==e.target.label).visiblelayers to a function that converts XML to an ArrayCollection.
private function convertXMLtoArrayCollection(file:XMLList):ArrayCollection{
var xml:XMLDocument = new XMLDocument(file);
var decoder:SimpleXMLDecoder = new SimpleXMLDecoder;
var data:Object = decoder.decodeXML((xml));
var array:Array = ArrayUtil.toArray(data);
return new ArrayCollection(array);
}
For the "Backscatter" layer with only one visiblelayers node, I get the expected ArrayCollection returned.
But the other two layers returns an ArrayCollection with the visibleLayers node added in.
Why isn't it returning an ArrayCollection like this?
I ended up using the following function to return an ArrayCollection that was suitable for my code:
private function convertXMLtoArrayCollection1(file:XMLList):ArrayCollection
{
var arrcol:ArrayCollection = new ArrayCollection;
for each (var value:* in file)
{
arrcol.addItem(value)
}
return arrcol;
}
For Converting XML to ArrayCollection or Array in ActionScript Example please visit the following link there explain with example.
Converting XML to ArrayCollection or Array in ActionScript Example
http://javafws.blogspot.in/2013/12/xml-to-arraycollection-or-array-in.html
精彩评论