Developer Developer - 1 month ago 14x
Perl Question

Get a Xml Tag value from regular expression in Perl

I have xml in which i have tag

.I want to get the value of the tag.I want to do it with Perl Regular Expression
Below is my xml sample :

<?xml version="1.0"?>

I want to get the value of this tag
.I tried but i am not able to get the value .

$data = ($xml =~/<test>(.*?)<\/test>/i);

In the xml i am getting xml like also

<Test RequestId="1" RequestorId="test" ResponderId="Test">

How could i get the value of


The $xml =~/<test>(.*?)<\/test>/i expression can be evaluated in list context in which case it returns an array with all the captured groups. So you need to do something like that:

($data) = $xml =~/<test>(.*?)<\/test>/i;

Edit: For the second example, you can similarly extract the information if you capture it with a set of parentheses:

($RequestorId) = $xml =~ /<Test [^>]*\bRequestorId="([^"]*)"/;