title: adding a new node in XML file via PHP
body: <p>I just wanted to ask how I can insert a new node in an XML using PHP. my XML file (questions.xml) is given below</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;Quiz&gt;
     &lt;topic text=&quot;Preparation for Exam&quot;&gt;
        &lt;subtopic text=&quot;Science&quot; /&gt;
        &lt;subtopic text=&quot;Maths&quot; /&gt;
        &lt;subtopic text=&quot;english&quot; /&gt;
     &lt;/topic&gt;
  &lt;/Quiz&gt;
  </code></pre>
  <p>I want to add a new &quot;subtopic&quot; with the &quot;text&quot; attribute, that is &quot;geography&quot;. How can I do this using PHP? Thanks in advance though.
  well my code is</p>
  <pre><code>&lt;?php
  
  $xmldoc = new DOMDocument();
  $xmldoc-&gt;load('questions.xml');
  
  
  $root = $xmldoc-&gt;firstChild;
  
  $newElement = $xmldoc-&gt;createElement('subtopic');
  $root-&gt;appendChild($newElement);
  // $newText = $xmldoc-&gt;createTextNode('geology');
  // $newElement-&gt;appendChild($newText);
  
  $xmldoc-&gt;save('questions.xml');
  ?&gt;
  </code></pre>