Perl XML DOM XPATH : Insert Values Using Perl
<p>I'm new to Perl XML:DOM XML:XPath (Have to use these only.)
How to insert values to the following xml file:
Need to Insert 1010, 1011 before 1020 in BadgeID (Using only Perl DOM &amp; XPath) 
Tried the following:</p>

<pre><code>#!/usr/bin/perl
use XML::DOM;
use XML::XPath;

my $mainFile = "badgelist.xml";
$xpmain = eval { XML::XPath-&gt;new( filename =&gt; $mainFile ); };

my $root = $main-&gt;getDocumentElement(); 
    my @list = $root-&gt;getElementsByTagName('Name');
    foreach my $key ( @list ) {
        if( $key-&gt;getFirstChild-&gt;getData eq 'Home' ) {

           $root-&gt;insertBefore($newparam, $genericMap);
           # Insert 1005, 1006 and 1007 before 1008

        }
    }



&lt;Badge-Lists&gt;
                &lt;List&gt;
                        &lt;Name&gt;Home&lt;/Name&gt;
                        &lt;Badges&gt;
                                        &lt;BadgeID&gt;1001&lt;/BadgeID&gt;
                                        &lt;BadgeID&gt;1008&lt;/BadgeID&gt;
                                        &lt;BadgeID&gt;1020&lt;/BadgeID&gt;
                        &lt;/Badges&gt;
                &lt;/List&gt; 

                &lt;List&gt;
                        &lt;Name&gt;Office&lt;/Name&gt;
                        &lt;Badges&gt;
                                        &lt;BadgeID&gt;5001&lt;/BadgeID&gt;
                                        &lt;BadgeID&gt;5012&lt;/BadgeID&gt;
                                        &lt;BadgeID&gt;5040&lt;/BadgeID&gt;
                        &lt;/Badges&gt;
                &lt;/List&gt;                 
&lt;/Badge-Lists&gt;
</code></pre>