title: add and element to xml file in perl
body: <p>I have an xml file as shown below:</p>
  
  <pre><code>&lt;root&gt;
   &lt;element1&gt;abc&lt;/element1&gt;
   &lt;element2&gt;123&lt;/element2&gt;
   &lt;element3&gt;456&lt;/element3&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>I am trying to add and element4 in perl using xml:dom</p>
  
  <pre><code>use XML::DOM;
  
  #parse the file
  my $parser = new XML::DOM::Parser;
  my $doc = $parser-&gt;parsefile ("mytest.xml");
  my $root = $doc-&gt;getDocumentElement();
  
  my $new_element= $doc-&gt;createElement("element4");
  my $new_element_text= $doc-&gt;createTextNode('testing');
  $new_element-&gt;appendChild($new_element_text);
  
  $root-&gt;appendChild($new_element);
  </code></pre>
  
  <p>I am getting the error:
  "Undefined subroutine &amp;XML::LibXML::Element::getNodeType "</p>
  
  <p>i tried insetBefore method to, by finding elements and tried to insert it before that. </p>
  
  <p>Any pointers, what am i doing wrong?</p>