XML and XMLList and XMLListCollection in Flex 3

2019-03-29 17:54发布

问题:

Please explain me what is the difference between XML and XMLList and XMLListCollection. If possible in simple words with example. Thanks in advance.

回答1:

First, links to Flex 3 Language Reference - a must have bookmark for looking this stuff up.

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/index.html

XML

XMLList

XMLListCollection

Secondly, I'd say check the Examples link for XMLList as that gives a good working example between the difference of XML and XMLList.

Use XML when you want to create a variable with a value of an XML document.

var mybooks:XML = <books>
  <book>
    <title>Book1</title>
  </book>
  <book>
     <title>Book2</title>
  </book>
</books>;

Use XMLList to create subsets of data from an XML variable.

var mybookTitles:XMLList = mybooks.title;  

Finally, an XMLListCollection class is basically a helper class for taking your XML or XMLList object and using it in a control.

Take this snippet from mx.core.Repeater docs on its dataProvider property

If you set it to an XML or XMLList, it is converted into an XMLListCollection.

Hope this helps



回答2:

An XMLListCollection is probably what you want to use. It has data binding and works well as a datasource in a datagrid.

An XMLListCollection is built from an XMLList. But after you have made an XMLListCollection from your XMLList, you rarely (if ever) use the XMLList again.

I rarely use XML. I think XML is mostly for backwards compatibility and that you are encouraged to use XMLList and XMLListCollection instead.