I'm not sure if I understand your requirement exactly, but here is a way to extract the values using XML::LibXML and Xpaths:
use XML::LibXML; my $doc = XML::LibXML->load_xml(string => $xml); my @mds = $doc->findnodes('//md'); for my $md ( @mds ) { my @mts = $md->findnodes('mi/mt'); next unless @mts; my @rs = $md->findnodes('mi/mv/r'); for my $i ( 0 .. $#mts ) { my ( $mt, $r ) = ( $mts[$i], $rs[$i] ); print "mt: ", $mt->textContent, "\n"; print "r: ", $r->textContent, "\n\n"; } }
Output using your example XML:
mt: pmPdcpPktDiscDlEth r: 0 mt: pmLicDlCapActual r: 0 mt: pmLicUlCapActual r: 0 mt: pmLicDlPrbCapActual r: 0 mt: pmLicUlPrbCapActual r: 0 mt: pmPdcpPktDiscDlEth r: 0 mt: pmPdcpPktDiscUlEthPacing r: 0 mt: pmLicDlCapDistr r: 81893,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 mt: pmLicUlCapDistr r: 90083,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 mt: pmLicDlPrbCapDistr r: 81893,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 mt: pmLicUlPrbCapDistr r: 90083,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

In reply to Re: Extract Data from XML (unique xml format?) by tangent
in thread Extract Data from XML (unique xml format?) by clapeters

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.