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

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

    released87 Level 1
      Hi,

      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...

      <blogs>
      <blog>
      <date></date>
      <title></title>
      <content></content>
      <comments>
      <comment>
      <name></name>
      <date></date>
      <title />
      <content></content>
      </comment>
      <comment>
      <name></name>
      <date></date>
      <title />
      <content></content>
      </comment>
      </comments>
      </blog>
      </blogs>

      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()">
      <mx:Script>
      <![CDATA[

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

      //Objects
      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
      [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;

      //Accessors

      //Methods
      private function sendXML():void {
      sendRequest.url= "XML/blog.xml";
      sendRequest.resultFormat= "e4x";
      sendRequest.send();
      sendRequest.addEventListener(ResultEvent.RESULT, loadXML);
      }
      private function loadXML(event:ResultEvent):void {
      requestXML= event.result as XML;
      blog_total= requestXML.blog.length();
      display();
      }
      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");
      }else{
      blog_ID++;
      display();
      }
      }
      private function previous():void {
      if(blog_ID >0){
      blog_ID--;
      display();
      }else{
      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>);
      updateXML();
      }

      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;
      updateXML();
      }
      public function deleteBlog():void {
      delete requestXML.blog[blog_ID];
      updateXML();
      }
      private function updateXML():void {
      variables.action= "edit_blog";
      variables.xmlString= requestXML;
      updateRequest.url= "PHP/actions.php";
      updateRequest.send(variables);
      updateRequest.addEventListener(ResultEvent.RESULT, updateComplete);
      }
      private function updateComplete(event:ResultEvent):void {
      Alert.show("Blog Updated");
      display();
      }
      ]]>
      </mx:Script>
      <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()" />
      </mx:ApplicationControlBar>
      </mx:Box>

      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
      Jesse