title: How to save changed SimpleXML object back to file?
body: <p>So, I have this code that searches for a particular node in my XML file, unsets an existing node and inserts a brand new child node with the correct data.  Is there a way of getting this new data to save within the actual XML file with simpleXML?  If not, is there another efficient method for doing this?</p>
  
  <pre><code>public function hint_insert() {
  
      foreach($this-&gt;hints as $key =&gt; $value) {
  
          $filename = $this-&gt;get_qid_filename($key);
  
          echo "$key - $filename - $value[0]&lt;br&gt;";
  
          //insert hint within right node using simplexml
          $xml = simplexml_load_file($filename);
  
          foreach ($xml-&gt;PrintQuestion as $PrintQuestion) {
  
              unset($xml-&gt;PrintQuestion-&gt;content-&gt;multichoice-&gt;feedback-&gt;hint-&gt;Passage);
  
              $xml-&gt;PrintQuestion-&gt;content-&gt;multichoice-&gt;feedback-&gt;hint-&gt;addChild('Passage', $value[0]);
  
              echo("&lt;pre&gt;" . print_r($PrintQuestion) . "&lt;/pre&gt;");
              return;
  
          }
  
      }
  
  }
  </code></pre>