i am trying to update xml element value using XML::Simple::XM Lin .But when I am again trying to retrive the XML data as it was before using XML::Simple::XM Lout.
But finding a deviation in the format can any pls help me out with same xml file structure.
input file:
Output file after execute:
Perl code:
Expected result:
But finding a deviation in the format can any pls help me out with same xml file structure.
input file:
Code:
<NavigationMap> <PageLink> <LinkText/> <url>/ae/index.html</url> <Domain>//www.fedex.com</Domain> <Protocol>UnSecure</Protocol> <Target/> <LinkParams/> </PageLink> <ImageSource alt="FedEx Home">//images.fedex.com/images/c/t1/gh/logo-header-fedex-express.png</ImageSource> </Logo> </NavigationMap>
Code:
<NavigationMap lastId="146"> <Logo> <ImageSource alt="FedEx Home">//images.fedex.com/images/c/t1/gh/logo-header-fedex-express.png</ImageSource> <PageLink> <Domain>//www.fedex.com</Domain> <LinkParams></LinkParams> <LinkText></LinkText> <Protocol>UnSecure</Protocol> <Target></Target> <url>/zw/index.html</url> </PageLink> </Logo> </NavigationMap>
Code:
$data = $xml -> parse_file($file_in,ForceArray => 1,KeyAttr =>[]);
foreach $TabEle (@{$data->{Logo}}) # retrieving list of values under Tab element
{
foreach $NameEle (@{$TabEle->{PageLink}}){
foreach $LinktxtEle(@{$NameEle->{Protocol}}){
print $LinktxtEle;
}
}
}
XMLout($data,rootname => 'NavigationMap',KeyAttr =>[],OutputFile => $file_in,NoSort => 1); #Writing xml back with updated value.
}
Code:
<NavigationMap lastId="146"> <PageLink> <LinkText/> <url>/ae/index.html</url> <Domain>//www.fedex.com</Domain> <Protocol>UnSecure</Protocol> <Target/> <LinkParams/> </PageLink> <ImageSource alt="FedEx Home">//images.fedex.com/images/c/t1/gh/logo-header-fedex-express.png</ImageSource> </Logo> </NavigationMap>
Comment