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<?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>
#!/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"; }
In reply to Reading multi-level-tag XML file by CSharma
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |