[英]How do I retrieve the node name from XML in Flex / Actionscript
I have some data xml data that looks like this 我有一些看起来像这样的数据xml数据
<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 results:XMLList = xml.configuration.*; var结果:XMLList = xml.configuration。*;
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 现在,我想遍历XMLList并输出CLICK,KLT,DETd等。但是如何在XML中这样获得节点名称?
XML: XML:
<root>
<parentNode>
<childNode1>1</childNode1>
<childNode2>2</childNode2>
<childNode3>3</childNode3>
</parentNode>
</root>
All you need to do is use .name()
while iterating through parentNode
's children()
. 您需要做的就是在迭代parentNode
的children()
时使用.name()
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
More: 更多:
Just use the name as the accessor. 只需使用名称作为访问器即可。
for each (var prop:XML in xml.configuration.*)
{
trace(prop.name());
}
You had xml.configuration.*
listing what was needed, so you were half-way there. 您有xml.configuration.*
列出了所需的内容,因此您已经完成了一半。 Just take each element as an XML in the iteration (with a for each loop). 只需在迭代中将每个元素都作为XML(每个循环都带有)即可。
You can use the name() method on any XML node, like so: 您可以在任何XML节点上使用name()方法,如下所示:
for each(var n:XML in results){
trace(n.name());
}
Will output: 将输出:
CLICK
KLT
DETd
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.