I have an xml file as shown below:
<root>
<element1>abc</element1>
<element2>123</element2>
<element3>456</element3>
</root>
I am trying to add element4 to perl using xml: dom
use XML::DOM;
my $parser = new XML::DOM::Parser;
my $doc = $parser->parsefile ("mytest.xml");
my $root = $doc->getDocumentElement();
my $new_element= $doc->createElement("element4");
my $new_element_text= $doc->createTextNode('testing');
$new_element->appendChild($new_element_text);
$root->appendChild($new_element);
I get an error: "Undefined routine & XML :: LibXML :: Element :: getNodeType"
I tried the insetBefore method, finding the elements and tried to insert it before that.
Any pointers what am I doing wrong?
source
share