Retrieving XML Data into mxml file
Hello Friends,
Today i am going to tell you how to retrieve data from a remote xml file into our flex application's mxml file.
These are the steps
1) Create a Employees.xml file. (from which we will retrieve data)
xml file contains the detailing of all employees as name, office no. address etc.
2) Create your mxml file into your flex project. (Name - simpleForm.mxml)
Now change some line of codes in mxml file
A) In the first <s:Application> tag add a line
creationComplete="employeeService.send()"
B) In the next <fx:Declaration> tag add httpServiceId and give the url of your xml file
<fx:Declarations>
<s:HTTPService id ="employeeService"
url="C:\Users\P\Adobe Flash Builder 4\FirstProject\src\Employees.xml" />
<s:HTTPService id ="employeeService"
url="C:\Users\P\Adobe Flash Builder 4\FirstProject\src\Employees.xml" />
</fx:Declarations>
C) Now your xml data is ready to use. Now to display the data, in the mxml
To display the first name of employees in the drop down list
<s:DropDownList id = "dropDownList1"
dataProvider="{employeeService.lastResult.Employees.employee}"
labelField="firstName">
dataProvider="{employeeService.lastResult.Employees.employee}"
labelField="firstName">
</s:DropDownList>
D) Now in the next text box we will show the office No. of the employee whose name is selected from the above drop down
<s:TextInput id="officeNo"
text = "{dropDownList1.selectedItem.phone}">
</s:TextInput>
text = "{dropDownList1.selectedItem.phone}">
</s:TextInput>
In this manner you can add any field of xml to any control of your mxml file.
This is the first screen where the data is shown in the drop down. Now when you select a name from a drop down, cooresponding office no. will be shown in the next text box as the next screen shows.