如何从XML中的Flex /动作脚本检索节点名节点、脚本、动作、XML

2023-09-08 14:02:06 作者:罂粟一样的女人°

我有一些看起来像这样的数据的XML数据

I have some data xml data that looks like this

<root xsi:noNamespaceSchemaLocation="test1.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <configuration>
    <CLICK/>
    <KLT/>
    <DETd/>
  </configuration>
</root>

我得到使用配置的列表

I get a list of the configurations using

VAR结果:返回XMLList = xml.configuration *;

var results:XMLList = xml.configuration.*;

现在我想遍历XMLList并输出CLICK,康莱特,DETd等,但如何在XML中我得到的节点名,例如

Now I want to loop over the XMLList and output CLICK, KLT, DETd etc. but how in XML do I get the node name as such

推荐答案

XML:

<root>
    <parentNode>
        <childNode1>1</childNode1>
        <childNode2>2</childNode2>
        <childNode3>3</childNode3>
    </parentNode>
</root>

所有你需要做的是使用。名称()同时通过 parentNode 的迭代儿童()

All you need to do is use .name() while iterating through parentNode's children().

for(var i:int=0;i<xml.children()[0].children().length();i++)
{
    var currentNode:XML = xml.children()[0].children()[i];
    trace(currentNode.name());
}

//childNode1
//childNode2
//childNode3

更多:

的http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/XMLList.html http://help.adobe.com/en_US/ FlashPlatform /参考/动作/ 3 / XML.html http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/XMLList.html http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/XML.html