CSharma has asked for the wisdom of the Perl Monks concerning the following question:
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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Reading multi-level-tag XML file
by choroba (Cardinal) on Jul 27, 2015 at 14:48 UTC | |
by CSharma (Sexton) on Jul 27, 2015 at 16:28 UTC | |
by poj (Abbot) on Jul 27, 2015 at 19:57 UTC | |
by CSharma (Sexton) on Jul 28, 2015 at 06:46 UTC | |
|
Re: Reading multi-level-tag XML file
by poj (Abbot) on Jul 27, 2015 at 15:29 UTC | |
|
Re: Reading multi-level-tag XML file
by choroba (Cardinal) on Jul 27, 2015 at 15:56 UTC | |
|
Re: Reading multi-level-tag XML file
by runrig (Abbot) on Jul 27, 2015 at 16:35 UTC | |
|
Re: Reading multi-level-tag XML file
by GotToBTru (Prior) on Jul 27, 2015 at 14:40 UTC | |
|
Re: Reading multi-level-tag XML file
by Hermano23 (Beadle) on Jul 27, 2015 at 14:46 UTC | |
|
Re: Reading multi-level-tag XML file
by Jenda (Abbot) on Oct 13, 2015 at 11:55 UTC |