1 Reply Latest reply on Mar 30, 2009 6:45 PM by released87

    Please help before I pull out the rest of my hair!!


      I have been trying very hard to understand what the problem I have been having is. Basically I am loading an external XML file into my FLEX app. I have add/update/delete functions that basically alter the existing XML tree. Everything is altered fine, as when I use Alert.show() to view the altered XML it is exactly how I wanted it. When it is altered I have it sent using http service to a PHP script that simply overwrites the existing file with the new altered XML. However, it seems that it will not send the XML, although it will send other values. I have tried copying the output XML and placing it in the PHP file and it works fine. There is definately something going wrong when sending the formatted XML to the PHP script. I have tried many combinations of .toString() and .toXMLString(). It seems complex XML will not work, as I have only had problems with this technique using the Rich Text Editor and with complex XML , such as the following structure...

      <title />
      <title />

      My Flex page looks like this:
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Box xmlns:mx=" http://www.adobe.com/2006/mxml" width="100%" height="100%" creationComplete="sendXML()">

      import mx.controls.Alert;
      import mx.rpc.events.ResultEvent;
      import mx.rpc.http.HTTPService;
      import mx.collections.XMLListCollection;

      private var sendRequest:HTTPService= new HTTPService();
      private var updateRequest:HTTPService= new HTTPService();
      private var variables:Object= new Object();
      private var requestXML:XML= new XML();
      private var requestList:XMLList= new XMLList();
      [Bindable] private var requestData:XMLListCollection= new XMLListCollection();

      [Bindable] private var blog_date:Date;
      [Bindable] private var blog_title:String;
      [Bindable] private var blog_content:String;
      [Bindable] private var blog_ID:int= 0;
      [Bindable] private var blog_total:int;


      private function sendXML():void {
      sendRequest.url= "XML/blog.xml";
      sendRequest.resultFormat= "e4x";
      sendRequest.addEventListener(ResultEvent.RESULT, loadXML);
      private function loadXML(event:ResultEvent):void {
      requestXML= event.result as XML;
      blog_total= requestXML.blog.length();
      private function display():void {
      blog_title= requestXML.blog[blog_ID].title;
      //blog_date= requestXML.blog[blog_ID].date;
      blog_content= requestXML.blog[blog_ID].content;
      private function next():void {
      if(blog_ID+1== blog_total){
      Alert.show("No more blogs");
      private function previous():void {
      if(blog_ID >0){
      Alert.show("No more blogs");
      private function addBlog():void {
      blog_date= input_date.selectedDate;
      blog_title= input_title.text;
      blog_content= input_blog.text;
      requestXML.prependChild(<blog><date>{blog_date}</date><title>{blog_title}</title><content >{blog_content}</content><comments><comment /></comments></blog>);

      public function editBlog():void {
      requestXML.blog[blog_ID].title= input_title.text;
      requestXML.blog[blog_ID].date= input_date.selectedDate;
      requestXML.blog[blog_ID].content= input_blog.text;
      public function deleteBlog():void {
      delete requestXML.blog[blog_ID];
      private function updateXML():void {
      variables.action= "edit_blog";
      variables.xmlString= requestXML;
      updateRequest.url= "PHP/actions.php";
      updateRequest.addEventListener(ResultEvent.RESULT, updateComplete);
      private function updateComplete(event:ResultEvent):void {
      Alert.show("Blog Updated");
      <mx:Label text="Title:" />
      <mx:TextInput id="input_title" text="{blog_title}"/>
      <mx:Label text="Date:" />
      <mx:DateChooser id="input_date" selectedDate="{blog_date}" />
      <mx:Label text="Blog:" />
      <mx:RichTextEditor id="input_blog" width="700" height="400" text="{blog_content}" title="Displaying Blog {blog_ID+1} of {blog_total}" />
      <mx:ApplicationControlBar width="820">
      <mx:Button label="Previous Blog" click="previous()" />
      <mx:Spacer width="100%" />
      <mx:Button label="Add Blog" click="addBlog()" />
      <mx:Button label="Edit Blog" click="editBlog()" />
      <mx:Button label="Delete Blog" click="deleteBlog()" />
      <mx:Spacer width="100%" />
      <mx:Button label="Next Blog" click="next()" />

      Please help, I have wasted so much time trying to figure this out!! There must be some formatting issue I am unaware of that is preventing Complex XML from being passed to the PHP when simpler XML works fine...

      Thanks in advance