Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 获取具有其父级名称的节点值_Xml_Actionscript 3 - Fatal编程技术网

Xml 获取具有其父级名称的节点值

Xml 获取具有其父级名称的节点值,xml,actionscript-3,Xml,Actionscript 3,如何获取父节点的名称?对于这个例子,我想知道它的父母喜欢什么; item>frames>front>enduro这是一种非常不方便且容易出错的从XML实例获取数据的方法 XML.children().children().children().children()[0]; //assets/helmet.jpg 包{ 导入flash.display.Sprite; 导入flash.text.TextField; 公共类XMLExample扩展了Sprite{ 公共函数XMLExample()

如何获取父节点的名称?对于这个例子,我想知道它的父母喜欢什么;
item>frames>front>enduro

这是一种非常不方便且容易出错的从XML实例获取数据的方法

XML.children().children().children().children()[0]; //assets/helmet.jpg 
包{
导入flash.display.Sprite;
导入flash.text.TextField;
公共类XMLExample扩展了Sprite{
公共函数XMLExample(){
常量数据:XML=
;
常量列表:XMLList=data..item,
parentName:String=list[0]。parent().name(),
textField:textField=newtextfield();
textField.text=父名称;
addChild(textField);
}
}
}
这将是一个简单的例子。当然,您应该通过方法访问某些数据

XML.children().children().children().children()[0]; //assets/helmet.jpg 
package {

  import flash.display.Sprite;
  import flash.text.TextField;

  public class XMLExample extends Sprite {

    public function XMLExample() {

      const data:XML =
          <root>
            <helmets>
              <enduro>
                <front>
                  <frames>
                    <item>
                      <![CDATA[assets/helmet.jpg]]>
                    </item>
                  </frames>
                </front>
              </enduro>
            </helmets>
          </root>;

      const list:XMLList = data..item,
          parentName:String = list[0].parent().name(),
          textField:TextField = new TextField();

      textField.text = parentName;
      addChild(textField);
    }
  }
}