Flex:将 XML 转换为具有多个节点的 ArrayCollection
我正在读取一个 XML 文件,其中树的分支如下所示:
<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>
</layer>
</data>
用户使用单选按钮选择图层,并在单击事件中传递图层。(@name==e.target.label)。 visiblelayers 为将 XML 转换为 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);
}
对于只有一个visiblelayers节点的“Backscatter”层,我得到了预期的ArrayCollection返回值。
但其他两层返回一个 ArrayCollection,其中添加了visibleLayers 节点。
为什么它不返回这样的 ArrayCollection?
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>
</layer>
</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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我最终使用以下函数返回适合我的代码的 ArrayCollection:
I ended up using the following function to return an ArrayCollection that was suitable for my code:
有关在 ActionScript 中将 XML 转换为 ArrayCollection 或数组的示例,请访问以下链接,其中有示例说明。
在 ActionScript 示例中将 XML 转换为 ArrayCollection 或数组
http://javafws.blogspot.in/2013 /12/xml-to-arraycollection-or-array-in.html
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