Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1482
  • Last Modified:

Flex 3 loading XML

Hi,

I'm trying to load a basic xml file and populate a standard datagrid. Then, I want to push a button to update the datagrid with fresh xml data from the file.

When i try to do this the data seems to be the old data after doing .send(); on the HTTPService even if the xml file has its content changed. I'm not trying to change the dataprovider. Only the contents of the xml is changed, same structure.
-------------FLEX CODE START-----------------
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="loadData(event)">
<mx:Script>
	<![CDATA[
		import mx.collections.ArrayCollection;
		import mx.rpc.events.ResultEvent;
		import mx.rpc.http.HTTPService;
		import mx.events.FlexEvent;
		import mx.rpc.soap.SOAPFault;       
        import mx.rpc.events.FaultEvent;
        import mx.controls.Alert;
		
	
			public function loadData(e:FlexEvent):void{
				test.url = 'test.xml';
				test.addEventListener(ResultEvent.RESULT, resultHandler);
				test.send();
				test.lastResult.refresh();
			}
			public function reload(e:MouseEvent):void{
				test.url = 'test.xml';
				test.send();
				test.lastResult.refresh();
				test.addEventListener(ResultEvent.RESULT, resultHandler);
				
				ta1.text += 'Kenneth';
			}
			
			public function resultHandler(e:ResultEvent):void {
				myDG.dataProvider = e.target.lastResult.book;
						
			}
			
			public function showErrorDialog(event:FaultEvent):void {
                // Handle operation fault.
                Alert.show(event.fault.faultString, "Error");
            }
            public function defaultFault(event:FaultEvent):void {
                // Handle service fault.
                if (event.fault is SOAPFault) {
                     var fault:SOAPFault=event.fault as SOAPFault;
                     var faultElement:XML=fault.element;
                     // You could use E4X to traverse the raw fault element returned in the SOAP envelope.
                     // ...
                }
                Alert.show(event.fault.faultString, "Error");               
            }
            public function log(event:ResultEvent):void {
                ta1.text += event.message.toString();
            }
	]]>
</mx:Script>
<mx:HTTPService id="test" url="test.xml" fault="showErrorDialog(event)" result="log(event)" resultFormat="e4x" />
	<mx:DataGrid id="myDG" x="254" y="190">
		<mx:columns>
			<mx:DataGridColumn dataField="title"/>
			<mx:DataGridColumn dataField="author"/>
			<mx:DataGridColumn dataField="year"/>
			<mx:DataGridColumn dataField="price"/>
		</mx:columns>
	</mx:DataGrid>
	<mx:Button x="254" y="349" label="Last på nytt" id="last" click="reload(event)" />
	<mx:TextArea id="ta1" x="254" y="392" width="402" height="155"/>
	
</mx:Application>
----------------------------FLEX CODE STOP---------------------------
 
------------------XML CONTENTS START------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
<book category="COOKING">
  <title lang="en">Everyday Italian</title> 
  <author>Giada De Laurentiis</author> 
  <year>2005</year> 
  <price>30.00</price> 
</book>
<book category="CHILDREN">
  <title lang="en">Harry Potter</title> 
  <author>J K. Rowling</author> 
  <year>2005</year> 
  <price>29.99</price> 
</book>
<book category="CHILDREN">
  <title lang="en">Harry Potter</title> 
  <author>J K. Rowling</author> 
  <year>2005</year> 
  <price>29.99</price> 
</book>
<book category="CHILDREN">
  <title lang="en">Harry Potter</title> 
  <author>J K. Rowling</author> 
  <year>2005</year> 
  <price>29.99</price> 
</book>
</bookstore>
--------------------XML CONTENT STOP-------------------------

Open in new window

0
kenped
Asked:
kenped
  • 2
1 Solution
 
Jones911Commented:
If you reload the XML then your just reloading the same data?

Where are you actually updating the XML file?
0
 
kenpedAuthor Commented:
For this example I Launch the application,, read the xml ,, which works,, Then i manually change the xml file,,, add records,, manually (for test). I wont update the datagrid, and the HTTPService.send(); shows the same content. The same result if i use a php file that takes records from a db,, even I change the records in the db, the result is still the same from HTTPService.send();

0
 
Jones911Commented:
public function reload(e:MouseEvent):void{
                                test.url = 'test.xml';
                                test.send();
                                test.lastResult.refresh();
                                test.addEventListener(ResultEvent.RESULT, resultHandler);
                                myDG.dataProvider = e.target.lastResult.book;    /added this line

                                ta1.text += 'Kenneth';
                        }


Try this.
0

Featured Post

The Lifecycle Approach to Managing Security Policy

Managing application connectivity and security policies can be achieved more effectively when following a framework that automates repeatable processes and ensures that the right activities are performed in the right order.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now