使用元素运算符时无法从 XML 对象获取元素列表?

Can't get a list of elements from an XML object when using the elements operator?

我一直在使用这个 XML,但我无法获得包含元素运算符的节点列表:

<s:LinearGradient rotation="90" xmlns:s="library://ns.adobe.com/flex/spark">
  <s:GradientEntry color="0x000000" alpha="0.8"/>
  <s:GradientEntry color="0xFFFFFF" alpha="0.8"/>
</s:LinearGradient>

这是我的 AS3:

var fillXML:XML = <s:LinearGradient rotation="90" xmlns:s="library://ns.adobe.com/flex/spark">
      <s:GradientEntry color="0x000000" alpha="0.8"/>
      <s:GradientEntry color="0xFFFFFF" alpha="0.8"/>
    </s:LinearGradient>;

var entriesXML:XMLList;
var GRADIENT_ENTRY:String = "GradientEntry";
entriesXML = fillXML..entries;

if (entriesXML.length()==0) {
    entriesXML = fillXML.descendants(GRADIENT_ENTRY);

    if (entriesXML.length()==0) {
        entriesXML = fillXML.elements(GRADIENT_ENTRY);
    }
}

看来您必须使用 QName 对象进行搜索:

var fillXML:XML = <s:LinearGradient rotation="90" xmlns:s="library://ns.adobe.com/flex/spark">
      <s:GradientEntry color="0x000000" alpha="0.8"/>
      <s:GradientEntry color="0xFFFFFF" alpha="0.8"/>
    </s:LinearGradient>;

var entriesXML:XMLList;
var GRADIENT_ENTRY:String = "GradientEntry";
var qname:QName = new QName("library://ns.adobe.com/flex/spark", GRADIENT_ENTRY);

entriesXML = fillXML.elements(GRADIENT_ENTRY);;

if (entriesXML.length()==0) {
    entriesXML = fillXML.elements(qname);
}