1 Reply Latest reply on Feb 20, 2007 2:48 PM by peterent

    Accessing nodes of XMLList

      I'm not understanding how I'm supposed to access specific nodes of an XMLList object.
      My XMLList object is created from an HTTPService's lastResult. Then I am trying to access a specific node, but none of the syntax I have tried works. I am able to use the "for each in" syntax to loop through all of the nodes, so I know that the XML is coming in okay.

      Here's the MXML I have:
      <mx:HTTPService id="feedRequest" url="blahblahblah.html" useProxy="false" resultFormat="e4x" />
      <mx:XMLListCollection id="xc" source="{feedRequest.lastResult.*}"/>

      And the script:
      private function showSomething():void {

      where the XML looks like:
      <self label="This one" nodeUid="1.3"></self>

      Currently the showSomething alert shows nothing. I want to access the node titled "self."' How can I do that?

        • 1. Re: Accessing nodes of XMLList
          peterent Level 2
          The event result is the XML root node. In the XML you gave as an example, that's the <node> node. So:

          XML(event.result).nodeName() == "node".

          An XMLList is an Array-like object of all the nodes that meet a criteria. For example:

          var list:XMLList = event.result.self;

          This will be all of the <self> elements which are immediate children of the root, <node>. In your case, this should have a length of one:

          list.length() // note this is a function, not a property

          So: list[0] should be the <self> node. And list[0].@label should be "This one" and so forth.

          Your XMLListCollection would be better formed by: source="{feedRequest.lastResult.self}" since it requires an XMLList for the source.