开发者

Flex: Converting XML to ArrayCollection with more than one node

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.

Flex: Converting XML to ArrayCollection with more than one node

But the other two layers returns an ArrayCollection with the visibleLayers node added in.

Flex: Converting XML to ArrayCollection with more than one node

Why isn't it returning an ArrayCollection like this?

Flex: Converting XML to ArrayCollection with more than one node


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜