tags:

views:

150

answers:

2

I use DOM to read and write XML file but it don't work. My code like this:

<?
$dom=new DomDocument();
$dom->Load("http://localhost/xml/file.xml");
$root=$dom->documentElement;
...
$dom->Save("file.xml");

?>

It not work. But when i try $dom->Save("C://file.xml"); It work fine. I don't understand while it not work. Anybody can tel me how?? Thanks you.

A: 

Ensure the file exists (as is apparently does, since you seem to be overwriting the original file), then try

$dom->save(realpath('file.xml'));

(Although your code should work as it is. Are you looking in the right directory for the file?)

GZipp
A: 

Try providing path to your file to make sure it attempts to save to a directory that php has permission to write to. for instance try:

$dom->Save($_SERVER["PWD"] . "/file.xml");

(this will save to same directory as where your file is running).

Mohammad