perl script to update a xml file

Hi experts,

I have a set of xml files in folder which has the below field.
<mm:sessionID>157.235.206.12900397BE4:A</mm:sessionID>,
I need to update this field regularly with new session id, which I have it from a login file.

Can anyone tell me how to add a new value in <mm:sessionID> field in xml files
under the folder("/usr/home/automation/Sanity/xml/) using perl script?

Here is what I have

opendir(DIR, "/usr/home/automation/Sanity/xml/");
my @ssl = grep /\.xml$/, readdir(DIR); close(DIR);
foreach $ssl (@ssl) {
    
    open(SSL, "$ssl");
    my @in = <SSL>;
    close(SSL);
      foreach (@in) {
        s/sessionID/$SID/;
       }
}

Thanks

varma

If you want to replace mm:sessionID then use

s/(<\/|<)mm:sessionID>/$SID/g;

instead of

s/sessionID/$SID/;

Hi Pravin,
Thanks for the help,

I want to replace the value mentioned between <mm:sessionID> <\mm:sessionID>?
but one you send this will change the "<mm:sessionID>" only right?

varma

Yes, Then try this,

s/<mm:sessionID>(.+?)<\/mm:sessionID>/<mm:sessionID>$new_value<\/mm:sessionID>/;