Hi PerlMonks,
I'm new to perl, please help! I've XML file having tags like below and I'm using XML::Simple perl module.
<?xml version="1.0" encoding="UTF-8"?><DataFeed recordCount="1377">
<SellerInformation><Seller sellerIdFromProvider="527543">BarketShop.co
+m</Seller><TaxableLocationsCollection><TaxableLocation locationType="
+state" locationValue="FL">1</TaxableLocation></TaxableLocationsCollec
+tion><ShippingChargesCollection><ShippingCharge type="fixed"/></Shipp
+ingChargesCollection></SellerInformation>
<SellerInformation><Seller sellerIdFromProvider="452471">Global Indust
+rial</Seller>
<TaxableLocationsCollection>
<TaxableLocation locationType="state" locationValue="GA">1</TaxableLoc
+ation>
<TaxableLocation locationType="state" locationValue="NV">1</TaxableLoc
+ation>
<TaxableLocation locationType="state" locationValue="NJ">1</TaxableLoc
+ation>
<TaxableLocation locationType="state" locationValue="NY">1</TaxableLoc
+ation></TaxableLocationsCollection>
<ShippingChargesCollection>
<ShippingCharge type="fixed"/>
</ShippingChargesCollection>
</SellerInformation></DataFeed>
My requirement is to get sellerIdFromProvider and value of each locationValue i.e. sellerIdFromProvider=> 452471 and locationValue => GA, NV, NJ, NY. Using below code I'm able to get values for the first *SellerInformation* tag (Single value so can be accessed via hash) but not for the 2nd one as that has multiple TaxableLocation tags (Would be accessed as an array). So I need to write a code which can deal both the conditions.
Also I've to add comma seperated locationValue to another xml file (Which will be compared using sellerIdFromProvider. I think hashes would be used.
I hope I'm clear! Please help me out.
Thanks
CSharma
#!/usr/bin/perl
use XML::Simple;
use Data::Dumper;
$xml = new XML::Simple;
foreach $d (@{$data->{'SellerInformation'}}) {
print $d->{'Seller'}{'sellerIdFromProvider'} . "\n";
print $d->{'TaxableLocationsCollection'}{'TaxableLocation'}{'locationV
+alue'} . "\n";
}