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"; }

In reply to Reading multi-level-tag XML file by CSharma

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.