Welcome, Guest. Please login or register.
Did you miss your activation email?
05/22/12, 05:54
Home Help Search Login Register
News: Parsley Flex framework review featuring quiz application, in our Flex frameworks series
Flex SDK 4.5 mobile roadmap: begin with your mobile development
Swiz Flex framework review featuring quiz application
New homepage we release our new Homepage, take a look ...

+  Flash-db
|-+  Server side Scripting and Database Support
| |-+  Flash Remoting with AMF (Moderators: Flash-db, Musicman, Jorge Solis, papachan, nothingGrinder)
| | |-+  Create XML with AS3, send to PHP, make into DomDocument
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Print
Author Topic: Create XML with AS3, send to PHP, make into DomDocument  (Read 25398 times)
pxpxpx
Server what's that
*
Posts: 4


View Profile
« on: 05/22/08, 03:07 »

I would like to create the XML in AS3, then send this variable to a PHP method, and 'convert' it to a DOMDocument.  Creating the XML in AS3, and sending/communicating with AMFPHP are not the issues for me.  Rather, inside the PHP method, having received the XML variable, how do I 'convert' it to a DomDocument?

For example (I'm using Caringorm here, this is a Flex application):
AS3:
public function delegateAction():void
{
   var xml:XML = <library><book>Some Book Title</book><book>Some Other Book Title</book></library>;   
         
   var call:Object = this.service.CreateXMLFile( xml );
   call.addResponder( this.responder );   
}

PHP:
public function CreateXMLFile($incomingXml)
{
         //What do I do here to get $incomingXML to be a DOMDocument?

        $xmlDoc = new DOMDocument('1.0', 'ISO-8859-1');
        $xmlDoc->formatOutput = true;  //these 2 lines are great, but I don't what to do next.

         //Or, better yet even, how can I ADD $incomingXML to $xmlDoc??

}

Many thank you's for any assistance.  I'm far, far more comfortable in AS3.  I'm not nearly as comfortable in PHP, so perhaps this is simple.
Logged
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14600


View Profile
« Reply #1 on: 05/22/08, 04:55 »

DOM interface is very expensive in resources, using XML for any other operation than reading is not a good choice
DOM commands summary: http://php.net/manual/es/ref.domxml.php

Jorge
Logged

pxpxpx
Server what's that
*
Posts: 4


View Profile
« Reply #2 on: 05/22/08, 11:09 »

Jorge,

    I appreciate what you're saying.  I still feel like it makes sense on this occasion.  These XML files will only be read from (using  AS3) the great, great majority of the time.  Nonetheless, I am creating a Flex interface to facilitate the very occasional editing of a couple of XML files for clients/customers of mine.  I won't bore you with all the details, whys, etc.

    I will look over the link you posted.  Thank you.
Logged
pxpxpx
Server what's that
*
Posts: 4


View Profile
« Reply #3 on: 05/26/08, 16:57 »

Thank you again to Jorge for his suggestions and getting me on the right path.
I am posting here how I finally accomplished what I wanted to do.

As recommended by Jorge, I started here (http://www.php.net/manual/en/ref.domxml.php).
Then jumped to here (http://www.php.net/manual/en/function.domxml-open-mem.php).  I had been attempting this method/function previously, but didn't get why it wasn't working for me.  Farther down on this last link though, there was a post stating, ...

"Although undocumented, domxml_open_mem does not exist in PHP5.  See this site for a quick fix:
http://alexandre.alapetite.net/doc-alex/domxml-php4-php5/index.en.html"

...so, went to the quoted link, got a class that made up for this method not being in my version of PHP, and my resulting, final, working code is posted below.

I am posting here 1 AS3 function, and 1 PHP function.  In my AS3 code, I'm using the Cairngorm Service to Worker Pattern, so there's obviously a good bit of code I'm not posting here. I'm just laying out here the two key functions that are related to my initial question.

Again, to be clear, my purpose was to create the XML in AS3, and use PHP to save the XML file to the server.  I haven't much experience at all with PHP, so if someone has thoughts on a better way to accomplish this, please feel free to post.  I'm always open to learn.

================
AS3 function:
public function delegateAction():void
{
   var xml:XML =
   <xml>
      <page label="Home" isPage="true" urlName="home" showOnMenu="true" title="Home">
         <xmlPath dl="" tag=""></xmlPath>
         <bmpPath dl="" tag=""></bmpPath>
         <swfPath dl="" tag=""></swfPath>
      </page>
   </xml>;
         
         
   var call:Object = this.service.SaveXMLFile( xml.toXMLString() );
   call.addResponder( this.responder );   
}

PHP function:

public function SaveXMLFile($incomingXml)
{
   if (version_compare(PHP_VERSION,'5','>='))
       require_once('domxml-php4-to-php5.php');
      
   $topHeader = '<?xml version="1.0" encoding="ISO-8859-1"?>';
   $incomingXml = $topHeader . $incomingXml;
      
   $xmlDoc = domxml_open_mem($incomingXml);
      
   $result = $xmlDoc->dump_file("myFile.xml");
      
   if($result == false)
   {
      return false;
   }
   else
   {
      return true;
   }
}
================
Logged
Ronald Wernecke
Administrator
Systems Administrator
*****
Posts: 6175


View Profile WWW Email
« Reply #4 on: 05/27/08, 01:46 »

If only Flash, or Flex will read/Write the XML-File, PHP has nothing to do with the structure.
You can just save or read it as a textfile.
The rest is done in Flash/Flex - so basicly the functionality of Jorges Loading and Saving tutorial with textfiles.
Logged

happy flashing
Cool
Ronald
pxpxpx
Server what's that
*
Posts: 4


View Profile
« Reply #5 on: 05/28/08, 12:11 »

Ronald,
  Well, in spite of my searching I was not aware of that approach.  I assume this is the link you are talking about (http://www.flash-db.com/Tutorials/savingAS3/).  Thank very much.  I'll look into that.  Thank you again.
Logged
ealbrecht
Server what's that
*
Posts: 1


View Profile
« Reply #6 on: 06/16/09, 13:43 »

Hi, I have tested this and it works and doesn't require all the extra workaround that you guys were talking about.

Flash/AS3
Code:
function sendXML():void
{
var variables:URLVariables = new URLVariables();
var myxml:String = xmlData.toString();
variables.myxml = myxml;

var req:URLRequest = new URLRequest("http://mywebsite/saveXML.php");
req.method = URLRequestMethod.POST;
req.data = variables;

ldr = new URLLoader(req);
ldr.addEventListener(Event.COMPLETE, ldr_onComplete);
ldr.dataFormat = URLLoaderDataFormat.VARIABLES;
ldr.load(req);

trace("sending message");
}
var ldr:URLLoader;
function ldr_onComplete( event:Event ) : void
{
var variables:URLVariables = new URLVariables( event.target.data );
ldr.removeEventListener(Event.COMPLETE, ldr_onComplete);

var result:String = variables.success=="1" ? Successfully saved XML!" : "Failed to save XML.";
trace(result);
}

PHP
Code:
<?php
$root_xml 
simplexml_load_string(<?xml version="1.0" encoding="utf-8" ?>
'.$_POST['myxml']);
$root_xml->asXML('test.xml');

echo "success=1";
?>
Logged
Ronald Wernecke
Administrator
Systems Administrator
*****
Posts: 6175


View Profile WWW Email
« Reply #7 on: 06/17/09, 03:12 »

you're funny - this is nothing but writing a xml file to the server.
Logged

happy flashing
Cool
Ronald
Pages: [1] Print 
« previous next »
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!