Sure, but you'll have to decide on a data structure
#!/usr/bin/perl --
use strict;
use warnings;
use XML::Twig;
my $xml = <<'__XML__';
<?xml version="1.0" encoding="UTF-8"?>
<authenticationReports>
<generatedTime>Tue Sep 29 07:07:34 PDT 2009</generatedTime>
<appDeploymentFile name="app-deployment.properties.hklcp.trading">
<application name="hk">
<urlInfo>
<url>e/t/hk/accts_subscription</url>
<otherPrereq>HKPwdPreReq</otherPrereq>
</urlInfo>
<urlInfo>
<url>e/t/hk/accts_forms</url>
<otherPrereq>HKPwdPreReq</otherPrereq>
</urlInfo>
<urlInfo>
<url>e/t/hk/custtradingpage</url>
<otherPrereq>BasicPrereq</otherPrereq>
</urlInfo>
<urlInfo>
<url>e/t/hk/accts_userinfo</url>
<otherPrereq>HKPwdPreReq</otherPrereq>
</urlInfo>
<urlInfo>
<url>e/t/hk/headermain</url>
</urlInfo>
<urlInfo>
<url>e/t/hk/custservicepage</url>
</urlInfo>
<urlInfo>
<url>e/t/hk/accts_transfermoney</url>
<otherPrereq>HKPwdPreReq</otherPrereq>
</urlInfo>
<urlInfo>
<url>e/t/hk/userprereq</url>
</urlInfo>
<urlInfo>
<url>e/t/hk/indices_us</url>
</urlInfo>
<urlInfo>
<url>e/t/hk/homeloggedmessage</url>
</urlInfo>
<urlInfo>
<url>e/t/hk/lead</url>
</urlInfo>
<urlInfo>
<url>e/t/hk/orderviewmin</url>
</urlInfo>
<urlInfo>
<url>e/t/hk/accts_changelogin</url>
<otherPrereq>SessionPreReq</otherPrereq>
</urlInfo>
</application>
<application name="intl">
<urlInfo>
<url>e/t/intl/quotesandresearch</url>
</urlInfo>
<urlInfo>
<url>e/t/intl/intltablesubnavviewcomponent</url>
</urlInfo>
<urlInfo>
<url>e/t/intl/intltablemetaviewcomponent</url>
</urlInfo>
<urlInfo>
<url>e/t/intl/disclaimer</url>
</urlInfo>
<urlInfo>
<url>e/t/intl/headermain</url>
</urlInfo>
<urlInfo>
<url>e/t/intl/indices_us</url>
</urlInfo>
<urlInfo>
<url>e/t/intl/lead</url>
</urlInfo>
<urlInfo>
<url>e/t/intl/selectlanguage</url>
</urlInfo>
<urlInfo>
<url>e/t/intl/get-screen</url>
<otherPrereq>BasicPrereq</otherPrereq>
</urlInfo>
<urlInfo>
<url>e/t/intl/page_f</url>
</urlInfo>
<urlInfo>
<url>e/t/intl/basicprereq</url>
</urlInfo>
<urlInfo>
<url>e/t/intl/page</url>
<otherPrereq>BasicPrereq</otherPrereq>
</urlInfo>
</application>
</appDeploymentFile>
</authenticationReports>
__XML__
# REUSING $xml
# SEE http://search.cpan.org/perldoc?XML::Twig#xparse
# $xml = appDeploymentFile('xmlexample.xml');
$xml = appDeploymentFile($xml);
use Data::Dumper();
print Data::Dumper->new([ $xml ])->Indent(1)->Dump;
sub appDeploymentFile {
my( $xml ) = @_;
my $url = "";
my %urls;
my $appFileName = "";
my $t = new XML::Twig(
start_tag_handlers => {
'appDeploymentFile' => sub {
my ( $twig, $tag, %att ) = @_;
#~ %att is only defined when twig_handlers
#~ $_ is only defined when twig_roots
#~ twig_handlers is uses less memory
$appFileName = $att{name} || $_->{'att'}->{name};
return;
},
},
twig_handlers => {
'appDeploymentFile/application/urlInfo/url' => sub {
$url = "/" . $_->text ;
$urls{ $url } = "";
return;
},
'appDeploymentFile/application/urlInfo/otherPrereq' => sub {
$urls{ $url } = $_->text ;
return;
},
},
);
$t->xparse($xml);
undef $t;
# REUSING $url
$url = join ":", "prd" , $1 , "web" , $2 if $appFileName =~ /\.([^\.
+]+?)\.([^\.]+?)$/;
return [ $appFileName , $url, \%urls ];
}
__END__
$VAR1 = [
'app-deployment.properties.hklcp.trading',
'prd:hklcp:web:trading',
{
'/e/t/intl/lead' => '',
'/e/t/intl/page_f' => '',
'/e/t/hk/userprereq' => '',
'/e/t/hk/custservicepage' => '',
'/e/t/intl/indices_us' => '',
'/e/t/intl/selectlanguage' => '',
'/e/t/intl/intltablemetaviewcomponent' => '',
'/e/t/intl/quotesandresearch' => '',
'/e/t/intl/headermain' => '',
'/e/t/intl/disclaimer' => '',
'/e/t/hk/accts_forms' => 'HKPwdPreReq',
'/e/t/hk/accts_userinfo' => 'HKPwdPreReq',
'/e/t/hk/accts_subscription' => 'HKPwdPreReq',
'/e/t/hk/indices_us' => '',
'/e/t/hk/orderviewmin' => '',
'/e/t/intl/get-screen' => 'BasicPrereq',
'/e/t/hk/custtradingpage' => 'BasicPrereq',
'/e/t/intl/basicprereq' => '',
'/e/t/hk/accts_changelogin' => 'SessionPreReq',
'/e/t/hk/accts_transfermoney' => 'HKPwdPreReq',
'/e/t/hk/homeloggedmessage' => '',
'/e/t/intl/intltablesubnavviewcomponent' => '',
'/e/t/intl/page' => 'BasicPrereq',
'/e/t/hk/lead' => '',
'/e/t/hk/headermain' => ''
}
];
|