tags:

views:

1484

answers:

3

Hello,

I'm using PHP to extract data from a MySQL database. I am able to build an XML file using DOM functions. Then using echo $dom->saveXML(); , I am able to return the XML from an AJAX call. Instead of using AJAX to get the XML, how would I save the XML file to a spot on the server? Thanks

+2  A: 

Doesn't DOMDocument::save() help you?

Ionuț G. Stan
+2  A: 

Use the DOMDocument::save() method to save the XML document into a file:

$dom->save('document.xml');
Gumbo
A: 

Besides "save" option of the DOM itself stated by two previous ansers, you could also use this piece of code:

$strxml = $dom->saveXML();
$handle = fopen("yourxmlfile.xml", "w");
fwrite($handle, $strxml);
fclose($handle);

And you are done.

Remember that the user running your application server (Apache, probably) will need permissions to write in the directory you are placing the XML file.

Pablo Santa Cruz