如何从Flex/Actionscript中的XML检索节点名称

Dal*_*ser 1 xml apache-flex actionscript-3

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

<root xsi:noNamespaceSchemaLocation="test1.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <configuration>
    <CLICK/>
    <KLT/>
    <DETd/>
  </configuration>
</root>
Run Code Online (Sandbox Code Playgroud)

我得到了一个配置列表

var结果:XMLList = xml.configuration.*;

现在我想循环遍历XMLList并输出CLICK,KLT,DETd等但是如何在XML中获取节点名称

小智 7

XML:

<root>
    <parentNode>
        <childNode1>1</childNode1>
        <childNode2>2</childNode2>
        <childNode3>3</childNode3>
    </parentNode>
</root>
Run Code Online (Sandbox Code Playgroud)

所有你需要做的是利用.name(),同时通过迭代parentNodechildren().

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
Run Code Online (Sandbox Code Playgroud)

更多:

  1. http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/XMLList.html
  2. http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/XML.html