title: How to save an XML file on the web server using PHP?
body: <p>I am a beginner in PHP and I know nothing about XML manipulation. I am working on a Google CSE annotation XML shown below:</p>
  
  <pre><code>  &lt;?xml version="1.0" encoding="UTF-8" ?&gt; 
  - &lt;Annotations&gt;
  - &lt;Annotation about="http://sanspace.in/"&gt;
    &lt;Label name="_cse_byxamvbyjpc" /&gt; 
    &lt;/Annotation&gt;
  - &lt;Annotation about="http://blog.sanspace.in/"&gt;
    &lt;Label name="_cse_byxamvbyjpc" /&gt; 
    &lt;/Annotation&gt;
  - &lt;Annotation about="http://google.com/"&gt;
    &lt;Label name="_cse_exclude_byxamvbyjpc" /&gt; 
    &lt;/Annotation&gt;
    &lt;/Annotations&gt;
  </code></pre>
  
  <p>I want achieve this from the above shown file:</p>
  
  <pre><code>  &lt;?xml version="1.0" encoding="UTF-8" ?&gt; 
  - &lt;Annotations&gt;
  - &lt;Annotation about="http://sanspace.in/"&gt;
    &lt;Label name="testString1" /&gt; 
    &lt;/Annotation&gt;
  - &lt;Annotation about="http://blog.sanspace.in/"&gt;
    &lt;Label name="testString2" /&gt; 
    &lt;/Annotation&gt;
  - &lt;Annotation about="http://google.com/"&gt;
    &lt;Label name="testString2" /&gt; 
    &lt;/Annotation&gt;
    &lt;/Annotations&gt;
  </code></pre>
  
  <p>So far, I have tried:</p>
  
  <pre><code>&lt;?php
  if (file_exists('test.xml'))
    {
    $xml = simplexml_load_file('test.xml');
    }
  else
    {
    exit('Error.');
    }
  foreach($xml-&gt;Annotation as $annotation)
      {
      if ($annotation["about"]=="http://sanspace.in/") 
          {  $annotation-&gt;Label["name"]="testString1";  } 
      else 
          {  $annotation-&gt;Label["name"]="testString2";  } } 
  
  $dom = new DOMDocument('1.0'); 
  $dom-&gt;preserveWhiteSpace = false; 
  $dom-&gt;formatOutput = true; 
  $dom-&gt;loadXML($xml-&gt;asXML()); 
  echo $dom-&gt;saveXML();
  $dom-&gt;save("test.xml");
  ?&gt; 
  </code></pre>
  
  <p>This code performs the task but it doesn't save it into the file.</p>
  
  <p>My question is, what's wrong with the <code>$dom-&gt;save("test.xml");</code> statement?
  How do I save the XML file on the server?</p>