Data Binding with XML Data Model in Flex4


 

Data Binding with XML Data Model in Flex4

The tag contains a data in tree format. It is just like a tag.

The tag contains a data in tree format. It is just like a tag.

Data Binding with XML DataModel in Flex4:

The <fx:XML> tag contains a data in tree format. It is just like a <fx:Model> tag.
The flex builder compiles the <fx:XML> tag into literal XML data. You can use this data in a component by using dataprovider property.
The tag is <fx:XML>.

The Syntax is given below.

<?xml version="1.0" encoding="utf-8"?>

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

xmlns:s="library://ns.adobe.com/flex/spark"

xmlns:mx="library://ns.adobe.com/flex/mx"

minWidth="955" minHeight="600">

<fx:Declarations>

<fx:XML id="employee" format="e4x">

<employee>

<name>

<first>{firstName.text}</first>

<last>{lastName.text}</last>

</name>

<department>{department.text}</department>

<email>{email.text}</email>

<phoneno>{phone.text}</phoneno>

</employee>

</fx:XML>

</fx:Declarations>

Example:

<?xml version="1.0" encoding="utf-8"?>

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

xmlns:s="library://ns.adobe.com/flex/spark"

xmlns:mx="library://ns.adobe.com/flex/mx"

minWidth="955" minHeight="600">

<fx:Declarations>

<fx:XML id="employee" format="e4x">

<employee>

<name>

<first>{firstName.text}</first>

0

<last>{lastName.text}</last>

</name>

<department>{department.text}</department>

1

<email>{email.text}</email>

<phoneno>{phone.text}</phoneno>

</employee>

2

</fx:XML>

</fx:Declarations>

<s:Panel title="Data Binding with XML DataModel" width="316" height="283">

3

<mx:Form x="14" y="14">

<mx:FormHeading label="Employee Information" textAlign="center"/>

<mx:FormItem label="First Name">

4

<s:TextInput id="firstName" width="134"/>

</mx:FormItem>

<mx:FormItem label="Last Name">

5

<s:TextInput id="lastName" width="134"/>

</mx:FormItem>

<mx:FormItem label="Department">

6

<s:TextInput id="department" width="134"/>

</mx:FormItem>

<mx:FormItem label="Email-id">

7

<s:TextInput id="email" width="134"/>

</mx:FormItem>

<mx:FormItem label="PhoneNo">

8

<s:TextInput id="phone" width="134"/>

</mx:FormItem>

<mx:FormItem direction="horizontal">

9

<s:Button id="Submitbtn" label="Submit" width="64"/>

<s:Button id="cancelbtn" label="Cancel" width="63"/>

</mx:FormItem>

0

</mx:Form>

</s:Panel>

</s:Application>

1

Output:

Running Application:

To view this page ensure that Adobe Flash Player version 10.0.0 or greater is installed.

Download this code

Ads