xmlactionscript-3flashe4x

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


I have been working with this XML and I'm not able to get a list of the nodes with the elements operator:

<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>

Here is my 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);
    }
}

Solution

  • It looks like you have to search using a QName object:

    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);
    }