in reply to Perl : How to retrieve from xml when xml file having same attribute multiple time

for my $cdr (@{$VAR1->{'cdr'}}){ my $info = $cdr->{'networkInfo'}; if ($info->{'requestType'} eq '1001'){ print $info->{'sessionId'}."\n"; # for example } }
poj
  • Comment on Re: Perl : How to retrieve from xml when xml file having same attribute multiple time
  • Download Code

Replies are listed 'Best First'.
Re^2: Perl : How to retrieve from xml when xml file having same attribute multiple time
by bhushanQA (Sexton) on Oct 14, 2015 at 15:51 UTC
    Hi Pijo, Thanks for your help and helping me to understand it clearly. As you have already looked into my question and understand it better way.. Can I ask you one more question ?? with your help I am able to retrieve the values from network info, but if I want to retrieve the values from 'payerInfo' and 'pricedInfo' based on the requestType 1001 from that particular section how can I proceed ?, as we can see there are so many sections .. and I don't want to deal with other only requestType 1001 and followed by 'payerInfo' and 'pricedInfo' of the same 'networkInfo' Thanks in Advance..!!
      for my $cdr (@{$VAR1->{'cdr'}}){ my $network = $cdr->{'networkInfo'}; if ($network->{'requestType'} eq '1001'){ my $payer = $cdr->{'payerInfo'}; my $priced = $cdr->{'pricedInfo'}; print $network->{'sessionId'}."\n"; print $payer->{'baseWalletBalance'}."\n"; print $priced->{'totalCostPrice'}."\n"; } }
      poj
        Thanks Pijo for help..!! It was working perfect if we take Array reference and multiple attributes present in the same file. But this is failing only one attribute is present in the file.. it says not an array reference.Below is my xml data dumper o/p.
        $VAR1 = { 'cdr' => { 'networkInfo' => { 'extPayer' => '13000', 'ggsnAddress' => '172.26.33.44', 'instanceId' => '0', 'imei' => '0', 'networkUsageIdentifier' => '172.2 +6.33.44', 'ReleaseCause' => '00144', 'spendControlId' => '0', 'defaultPayer' => '13000', 'gprsLocationInfo' => '0130120857' +, 'sessionId' => '151014195900000010 +1', 'errorCode' => '0', 'requestType' => '1001', 'timeZone' => '', 'ccRequestType' => '3', 'defaultExtPayer' => '13000', 'sgsnAddress' => '172.26.33.44', 'gprsLBC' => '0', 'gprsApn' => 'tecnotree.com', 'connectionType' => '0', 'gprsAttributes' => '', 'eventDateTime' => '20151014195959 +', 'imsiMccMnc' => '724110000000069', 'sequenceNumber' => '0', 'unitType' => '2', 'holidayCode' => '0', 'serviceIdentifier' => '0', 'ratingGroup' => '1029', 'pdpType' => '0', 'pdpAddress' => '172.26.33.44', 'sgsnMccMnc' => '', 'specialLocationClassId' => '0', 'eventType' => '0', 'payerType' => '0', 'connectionId' => '005029740902190 +', 'payer' => '13000', 'cgAddress' => '', 'redirectionCode' => '0', 'callReferenceNumber' => '11499269 +2', 'ggsnMccMnc' => '', 'mvnoId' => '3', 'originatingNetworkId' => '1081', 'chargingId' => '114992692', 'actionDateTime' => '2015101419595 +9', 'tariffToken' => '0', 'callTerminationCause' => '1', 'exponent' => '-6' }, 'payerInfo' => { 'newPayerStatus' => '2', 'noOfPayerValidity' => '0', 'prevPayerStatus' => '2', 'walletDetails' => { 'walletId' => '1' +, 'prevWalletBalanc +e' => '9856000000000', 'prevExpiryDate' +=> '20151202', 'expiryFlag' => ' +0', 'newWalletBalance +' => '9854000000000', 'newExpiryDate' = +> '20151202' }, 'noOfWalletsUsed' => '1', 'baseWalletBalance' => '985400000000 +0' }, 'pricedInfo' => { 'totalUsedUnits' => '2000', 'totalCostPrice' => '2000000000', 'bucket' => { 'rateId' => '1347', 'discountPercentage' => + '0', 'startUnits' => '1', 'exchangeRate' => '1000 +000', 'taxFormulaId' => '1002 +', 'componentId' => '0', 'taxWalletId' => '1', 'currencyRateId' => '1' +, 'discountArticleId' => +'1001', 'walletId' => '1', 'salePrice' => '2000000 +000', 'discountAmount' => '0' +, 'TaxDetail' => { 'Tax' => + { + 'amount' => '0', + 'count' => '1', + 'article' => '1009' } }, 'usedUnits' => '2000', 'endUnits' => '2000', 'taxApplied' => '0', 'debitedValue' => '2000 +000000', 'costPrice' => '2000000 +000', 'dimensionId' => '0', 'serviceKey' => '0', 'chargeArticleId' => '1 +', 'tariffId' => '1422' }, 'taxingOptionUsed' => '0', 'totalTax' => '0', 'totalSalePrice' => '2000000000', 'chargeSummary' => { 'dimensionSummar +y' => { + 'dimensionId' => '0', + 'componentSummary' => { + 'totalSalePrice' => '2000000000', + 'totalCostPrice' => '2000000000', + 'componentId' => '0', + 'totalDiscountAmount' => '0', + 'bucketsUsed' => '1' + } + } }, 'bucketsUsed' => '1', 'totalDiscountAmount' => '0' } } };
Re^2: Perl : How to retrieve from xml when xml file having same attribute multiple time
by bhushanQA (Sexton) on Oct 14, 2015 at 13:40 UTC
    Thanks Poj its working perfectly.. what a good solution :)