1 Reply Latest reply on Nov 30, 2007 1:07 PM by ntsiii


      I have an XML file which I want to read in an mxml file.

      <items country="USA">
      <item name="sales" value="12345" der="1.89"/>
      <item name="imports" value="4234" der="1.93"/>

      Now if I want to read the value of an attribute of item e.g name I can do that as follows:-
      var viewXMLList:XMLList = e.result.item;
      var len:Number = viewXMLList.length();
      for (var i:Number = 0; i < len; i++)
      var ttt:String = viewXMLList .@name;
      But apparently if I have only one items element and I try to read the value of country it doesnt work, cause

      var viewXMLList:XMLList = e.result.items;
      var len:Number = viewXMLList.length();

      and len comes out to be 0, am I missing something?
        • 1. Re: XML
          ntsiii Level 3
          If that is the exact format of your file, then "e.result" is already at the items node.
          var xmlResult:XML = XML(e.result);
          trace(xmlResult.toXMLString); //will show the xml above

          So "e.result.items" is really "items.items", which doesn't exist, and so returns an empty XMLList (len=0).

          Note that in you loop, you are overwriting ttt, not appending to it.