Hi Perl monks team,

I am trying to Parse multiple XML and Store the values into hashmap as Key/Value Pair.

I have tried to Parse multiple XML and Store the values into array as my certain fields has duplicate values so I want the unique value of it and store its corresponding values.

Does anyone can suggest me ideas?

I am unable to initiate it as I don't know how to store key/value pair in Hashmap. and sample of the XML is

<?xml version="1.0" encoding="utf-8"?> <!-- Configuration for the aero product --> <product name="aero" xsi:noNamespaceSchemaLocation="product.xsd" xmlns +:xsi="http://www.w3.org/2001/XMLSchema-instance"> <productName>Airtime</productName> <licenseName>Airtime_Tool</licenseName> <externalProductIdentifier>10</externalProductIdentifier> <baseCode>AT</baseCode> <released>true</released> <releasePlatforms> <platform>all</platform> </releasePlatforms> <dependsOn> <componentDep name="air"></componentDep> <componentDep name="air"></componentDep> <componentDep name="air"></componentDep> </dependsOn> <requiredProducts> <productDep name="air"></productDep> </requiredProducts> <releaseTypeAndDelivery> <releaseTD releaseType="PVersion" releaseDelivery="DVD"/> <releaseTD releaseType="PVersion" releaseDelivery="Web"/> <releaseTD releaseType="SVersion" releaseDelivery="Web"/> </releaseTypeAndDelivery> </product>

and I only need

<productName>Airtime</productName> <licenseName>Airtime_Tool</licenseName> <externalProductIdentifier>10</externalProductIdentifier> <baseCode>AT</baseCode> <product name =aero>

and I want to make licenseName as key and rest as a Values of it. I have tried it as

my $xmldata= XMLin($filename); foreach my $licenseName (keys %{$xmldata->{licenseName}}) { print $licenseName . ' is ' . $xmldata->{basecode}->{$basecode +} . $xmldata->{externalProductIdentifier}->{$externalProductIdentifie +r} . "\n"; }
Thanks!!!


In reply to Parsing multiple XML and Store the values into hashmap as Key/Value Pair by vaibhav.shukla

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.