?
Solved

i am unable to read the data from the xml file to data grid

Posted on 2009-04-28
13
Medium Priority
?
280 Views
Last Modified: 2012-06-27
the flex code in the eclipse
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
      <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.rpc.events.ResultEvent;
            
            [Bindable]
            
            private var employeeData:ArrayCollection;
            
            private function resultHandler(event:ResultEvent):void{
                  employeeData=event.result.employees.employee;
            }
      ]]>
</mx:Script>
<mx:HTTPService id="employeeservice" url="employees.xml"
      result="resultHandler(event)" />

<mx:DataGrid dataProvider="{employeeData}" >
<mx:columns>
<mx:DataGridColumn dataField="name" headerText="First Name" />
</mx:columns>
</mx:DataGrid>
</mx:Application>


and I created the xml file in the src folder the code for the xml is
<?xml version="1.0" encoding="UTF-8"?>
 <employees>
       <employee>
        <name>Colorado Room</name>
        <roomsize>20x20</roomsize>
        <cateringservice>Yes</cateringservice>
        <restroomlocation>Westside near elevator</restroomlocation>
        <capacity>150</capacity>
        <windows>South wall all glass, garden view</windows>
        <wheelchair_accessible>Yes</wheelchair_accessible>
        <description>The Colorado Room is a comfortable room for any type of event. It is a popular room so book now!</description>
        <stars>5</stars>
        <publictelephone_location>Entry level: North wall</publictelephone_location>
       </employee>
      
<employee>
        <name>Mile High Room</name>
        <roomsize>25x30</roomsize>
        <cateringservice>Yes</cateringservice>
        <restroomlocation>Westside near elevator</restroomlocation>
        <capacity>100</capacity>
        <windows>One window, north wall</windows>
        <wheelchair_accessible>Yes</wheelchair_accessible>
        <description>The Colorado Room is a comfortable room for any type of event. It is a popular room so book now!</description>
        <stars>3</stars>
        <publictelephone_location>Entry level: North wall</publictelephone_location>
</employee>

<employee>
        <name>Bronco Room</name>
        <roomsize>15x13</roomsize>
        <cateringservice>No</cateringservice>
        <restroomlocation>Eastside near elevator</restroomlocation>
        <capacity>75</capacity>
        <windows>None</windows>
        <wheelchair_accessible>Yes</wheelchair_accessible>
        <description>The Colorado Room is a comfortable room for any type of event. It is a popular room so book now!</description>
        <stars>4</stars>
        <publictelephone_location>Entry level: North wall</publictelephone_location>
 </employee>
 <employee>
  <name>Greeley Room</name>
  <roomsize>20x20</roomsize>
  <cateringservice>Yes</cateringservice>
  <restroomlocation>Westside near elevator</restroomlocation>
  <capacity>150</capacity>
  <windows>South wall all glass, garden view</windows>
  <wheelchair_accessible>Yes</wheelchair_accessible>
  <description>The Colorado Room is a comfortable room for any type of event. It is a popular room so book now!</description>
  <stars>1</stars>
  <publictelephone_location>Entry level: North wall</publictelephone_location>
</employee>
<employee>
 
  <name>Boulder Room</name>
  <roomsize>40x40</roomsize>
  <cateringservice>Yes</cateringservice>
  <restroomlocation>Westside near elevator</restroomlocation>
  <capacity>350</capacity>
  <windows>None</windows>
  <wheelchair_accessible>Yes</wheelchair_accessible>
  <description>The Colorado Room is a comfortable room for any type of event. It is a popular room so book now!</description>
  <stars>3</stars>
  <publictelephone_location>Entry level: North wall</publictelephone_location>
 </employee>
  </employees>

can any expert can help please
0
Comment
Question by:ukdasari
12 Comments
 
LVL 12

Expert Comment

by:lexxwern
ID: 24257374
You'll need to send the service .. ;-)

try this:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="applicationCreationCompleteHandler()">
<mx:Script>
      <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.rpc.events.ResultEvent;
            
            [Bindable]
            
            private var employeeData:ArrayCollection;
            
            private function resultHandler(event:ResultEvent):void{
                  employeeData=event.result.employees.employee;
            }
            
            private function applicationCreationCompleteHandler():void {
                employeeservice.send();
            }
      ]]>
</mx:Script>
<mx:HTTPService id="employeeservice" url="employees.xml"
      result="resultHandler(event)" />
 
<mx:DataGrid dataProvider="{employeeData}" >
<mx:columns>
<mx:DataGridColumn dataField="name" headerText="First Name" />
</mx:columns>
</mx:DataGrid>
</mx:Application>

Open in new window

0
 

Author Comment

by:ukdasari
ID: 24257501
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
      creationComplete="employeeservice.send()">
<mx:Script>
      <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.rpc.events.ResultEvent;
            
            [Bindable]
            
            private var employeeData:ArrayCollection;
            
            private function resultHandler(event:ResultEvent):void{
                  employeeData=event.result.employees.employee;
            }
      ]]>
</mx:Script>
<mx:HTTPService id="employeeservice" url="employees.xml"
      result="resultHandler(event)" resultFormat="e4x" />

<mx:DataGrid dataProvider="{employeeData}" >
<mx:columns>
<mx:DataGridColumn dataField="name" headerText="First Name" />
</mx:columns>
</mx:DataGrid>

</mx:Application>
0
 

Author Comment

by:ukdasari
ID: 24257504
thanx for the reply
this is the new code where i added the send service can you tell me what is the problem is please
0
Prepare for an Exciting Career in Cybersecurity

Help prevent cyber-threats and provide solutions to safeguard our global digital economy. Earn your MS in Cybersecurity. WGU’s MSCSIA degree program curriculum features two internationally recognized certifications from the EC-Council at no additional time or cost.

 
LVL 37

Accepted Solution

by:
zzynx earned 500 total points
ID: 24261583
This works for me.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
      creationComplete="onComplete()">
<mx:Script>
      <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.rpc.events.ResultEvent;
            
            private function onComplete():void {
            	dg.dataProvider = xmlData.employee;
            }
      ]]>
</mx:Script>
 
<mx:XML source="assets/Employees.xml" id="xmlData"/>
 
<mx:DataGrid id="dg" >
	<mx:columns>
		<mx:DataGridColumn dataField="name" headerText="First Name" />
	</mx:columns>
</mx:DataGrid>
</mx:Application>

Open in new window

0
 
LVL 37

Expert Comment

by:zzynx
ID: 24261605
Or to go short:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
      creationComplete="{dg.dataProvider = xmlData.employee;}">
 
<mx:XML source="assets/Employees.xml" id="xmlData"/>
 
<mx:DataGrid id="dg" >
	<mx:columns>
		<mx:DataGridColumn dataField="name" headerText="First Name" />
	</mx:columns>
</mx:DataGrid>
</mx:Application>

Open in new window

0
 

Author Comment

by:ukdasari
ID: 24275919
so i dont know what is the problem can anyone can help me please
0
 

Author Comment

by:ukdasari
ID: 24276215
hello
can anyone help me please i am not able to read the data from the xml sheet to the data grid so can anyone can tell me what is the problem
i am struck with this from one week
0
 
LVL 37

Expert Comment

by:zzynx
ID: 24278216
>> can anyone help me please
I thought I did in my previous comments...
0
 

Author Comment

by:ukdasari
ID: 24280215
yes i added the send method to the application
even i am getting same error
0
 
LVL 37

Expert Comment

by:zzynx
ID: 24280532
Please look at **MY** (zzynx) comments
0
 
LVL 37

Expert Comment

by:zzynx
ID: 24318911
I repeat:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
      creationComplete="{dg.dataProvider = xmlData.employee;}">
 
<mx:XML source="assets/Employees.xml" id="xmlData"/>
 
<mx:DataGrid id="dg" >
        <mx:columns>
                <mx:DataGridColumn dataField="name" headerText="First Name" />
        </mx:columns>
</mx:DataGrid>
</mx:Application>

Open in new window

0
 
LVL 29

Expert Comment

by:dgofman
ID: 37499038
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

 The Evil-ution of Network Security Threats

What are the hacks that forever changed the security industry? To answer that question, we created an exciting new eBook that takes you on a trip through hacking history. It explores the top hacks from the 80s to 2010s, why they mattered, and how the security industry responded.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
I came across an unsolved Outlook issue and here is my solution.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month14 days, 11 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question