-1

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);
    }
}
1.21 gigawatts
  • 16,517
  • 32
  • 123
  • 231
  • 1
    Do not [**delete your question marked as a duplicate**](http://stackoverflow.com/questions/40832158/cant-get-list-of-descendants-in-xml-node) and then repost it as a new question. That's why the [**re-open process**](http://meta.stackexchange.com/questions/36415/how-do-you-reopen-a-closed-question) exists. **Do not attempt to skirt the reopen process via deletion and reposting**. – kjhughes Nov 27 '16 at 19:03
  • The answer you linked to as a duplicate was not the same. Then you closed my question as I was writing the solution. The other question didn't have the same answer or the same details. I've been on this site for four years now and half my questions are marked as duplicates until after hours of arguing I've prove that they are not in fact duplicates. If they are duplicates then I'm glad to close them myself. – 1.21 gigawatts Nov 27 '16 at 19:07
  • It is a duplicate because your problem is a failure to account for the namespaces, and the linked question shows you how. (**There are many other past questions that cover this common mistake. Your question is far from unique.**) Regardless, you should have argued your case and petitioned for your question to be re-opened, not deleted it and reposted it. – kjhughes Nov 27 '16 at 19:11
  • The other question is a generic, low quality question. The answer is vague as well as it talks about creating a namespace and using e4x notation in general. It doesn't answer specific details. My question is specific and my answer is specific. It also provides example code and working solution code. – 1.21 gigawatts Nov 27 '16 at 19:11
  • Last time: [***Your question is not unique***](https://www.google.com/search?q=actionscript+xml+namespace+site:stackoverflow.com) and ***you're wrong to delete and repost to skirt the reopen process. Deleting is fine; [reposting to skirt the reopen process is not](http://meta.stackexchange.com/questions/176612/is-it-ok-to-to-delete-and-repost-a-duplicate-question)***. Good luck to you. I'm moving on. – kjhughes Nov 27 '16 at 19:16
  • When you close the question I can't write an answer. Maybe mark it as a duplicate and let me check? Then I'd be glad to close it or delete it myself. And I checked the top five results in your Google search none of them show the answer or question I was looking for. They are all creating namespaces. That is not specific to my case. I was looking for QName. It's a different problem and solution. Plus those answers linked to documentation off site. That goes against the StackOverflow philosophy of adding answers locally in case external links go down. – 1.21 gigawatts Nov 27 '16 at 19:22
  • 1
    @kjhughes Confusingly, the "marked as duplicate" blurb encourages one to post a new question if the linked answer doesn't fully help. You're saying that one should instead edit the existing question in hopes of getting it reopened, correct? I'm not sure what the right path is, here. – Brian Nov 29 '16 at 19:08
  • @1.21gigawatts The other question's answer looks like it ought to do the trick. What breaks when you try to use that approach? – Brian Nov 29 '16 at 19:11
  • @Brian The other question describes that you have to declare namespaces but doesn't really answer the question. Since I have dynamic XML I was avoiding that in case it collides with existing namespaces in the class. The solution I posted below returns an XMLList without creating any new namespaces by using a QName object. – 1.21 gigawatts Dec 03 '16 at 14:37

1 Answers1

1

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);
}
1.21 gigawatts
  • 16,517
  • 32
  • 123
  • 231