如何使用flex获取xml中父节点下的所有子节点?

时间:2021-07-02 20:20:28

I have a parent node and I'm trying to get each child node under that parent and store it into an arraycollection? How could I go by doing this?

我有一个父节点,我正在尝试获取该父节点下的每个子节点并将其存储到arraycollection中?我怎么能这样做?

1 个解决方案

#1


1  

var coll:ArrayCollection = new ArrayCollection();

for each ( var child:XML in parent.children()) {
    coll.add(child);
}

parent.children() gives you all child nodes of parent as XMLList. You can then add each child to the collection.

parent.children()为您提供父级的所有子节点作为XMLList。然后,您可以将每个子项添加到集合中。

If you want to include only element nodes, you can use elements() instead of children().

如果只想包含元素节点,可以使用elements()而不是children()。

#1


1  

var coll:ArrayCollection = new ArrayCollection();

for each ( var child:XML in parent.children()) {
    coll.add(child);
}

parent.children() gives you all child nodes of parent as XMLList. You can then add each child to the collection.

parent.children()为您提供父级的所有子节点作为XMLList。然后,您可以将每个子项添加到集合中。

If you want to include only element nodes, you can use elements() instead of children().

如果只想包含元素节点,可以使用elements()而不是children()。