Q:

How to change parameter value in XML using bash or perl?

I have a xml in below and need to modify some parameter value  

<test name="MyRawExample" preserve-order="true">
    <parameter name="example-parameter" value="11111" />
    <classes>
        <class name="com.ericol.nco.blocktests.example.ExampleTestcase" />
    </classes>
</test>

I need to look for a specific parameter name and then replace the corresponding value by a new input value and updates the xml file.
I was wondering if anybody can help me how I may change it or offer me a rigid doc so that i can find the most efficient script to accomplish this.
Regards,
Behzad

A:

As Mortiz mentioned, you should first make some effort to solve the problem.
With that in mind, gave a look at the XML::Twig Perl module. It will enable you do do what you want easily.
UPDATE: Since you've done some work and came up with some code, here's a working solution:
#!/usr/bin/perl -w
use strict;
use XML::Twig;

my $twig=XML::Twig->new(   
    twig_handlers => { 
        parameter  => sub {
            if ($_->att('name') eq 'example-parameter') {
                $_->set_att('value' => '22222') 
            }
        }
    },
    pretty_print => 'indented',
);

$twig->parsefile('src/main/resources/exampleSuite.xml');
$twig->flush;

I'll leave it to you to do the file replacement.

