| Flex 2 Developer's Guide > Flex Data Features > Binding Data > Binding data with the <mx:Binding> tag > Using an E4X expression in an <mx:Binding> tag | |||
A binding expression curly braces or an <mx:Binding> tag can contain an ECMAScript for XML (E4X) expression when the source of a binding is a bindable property of type XML. Unlike an E4X expression in curly braces, when you use an E4X expression in an <mx:Binding> tag, you must explicitly call the toString() method when the binding destination is a String property.
In the code in the following example, there are three binding expressions in curly braces that bind data from an XML object. The first uses . (dot) notation, the second uses .. (dot dot) notation, and the third uses || (or) notation.
<?xml version="1.0"?>
<!-- binding/E4XInBindingTag.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
width="600" height="900">
<mx:Script>
<![CDATA[
[Bindable]
public var xdata:XML =
<order>
<item id = "3456">
<description>Big Screen Television</description>
<price>1299.99</price><quantity>1</quantity>
</item>
<item id = "56789">
<description>DVD Player</description>
<price>399.99</price>
<quantity>1</quantity>
</item>
</order>;
]]>
</mx:Script>
<mx:Label text="Using .. notation."/>
<!-- This will update because what is
binded is actually the String and XMLList. -->
<mx:List width="75%" id="txts"/>
<mx:Binding
source="xdata..description"
destination="txts.dataProvider"/>
<mx:Label text="Using . notation."/>
<mx:List width="75%" id="txt2s"/>
<mx:Binding
source="xdata.item.description"
destination="txt2s.dataProvider"/>
<mx:Label text="Using || (or) notation."/>
<mx:List width="75%" id="txt3s"/>
<mx:Binding
source="xdata.item.(@id=='3456'||@id=='56789').description"
destination="txt3s.dataProvider"/>
</mx:Application>
Flex 2.01