例子:
然后authors里面就是<author>Author1</author>和<author>Author1</author>这两个节点的内容了。
node..author这个是一个E4X表达式,意思是从node表示的节点里找出所有author节点。
For example1:
如果你使用的HTtp service,在得到结果可以转换:
另一方法:
http://hillelcoren.com/2008/09/21/flex-tip-convert-xml-to-arraycollection/提供的方法:
This is one of those things that took me much longer than I thought it would have. I needed to convert a file containing XML data to an ArrayCollection. My XML file looked like this:
<rows> <row> <col1>some value</col1> <col2>another value</col2> ... </row> ... </rows>
I wanted to convert this into an ArrayCollection with each row as an object (and I didn’t want to have to loop through each item in the list). Here’s the solution I’m using.
import mx.utils.ArrayUtil; import mx.rpc.xml.SimpleXMLDecoder; import mx.collections.ArrayCollection; private function convertXmlToArrayCollection( file:String ):ArrayCollection { var xml:XMLDocument = new XMLDocument( file ); var decoder:SimpleXMLDecoder = new SimpleXMLDecoder(); var data:Object = decoder.decodeXML( xml ); var array:Array = ArrayUtil.toArray( data.rows.row ); return new ArrayCollection( array ); }
I’m not thrilled with this approach because I’ve needed to hard code the XML structure (’rows.row’) into the function. If anyone has a better solution I’d love to see it.