in reply to Extract Data from XML (unique xml format?)

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

Replies are listed 'Best First'.
Re^2: Extract Data from XML (unique xml format?)
by AjitKhodke (Initiate) on Jun 17, 2015 at 05:44 UTC
    use XML::LibXML; my $string = q| <Root> <Parent> <child1>Child 1</child1> <child2>Child 2</child2> <child3>Child 3</child3> </Parent> </Root>|; my $doc = XML::LibXML->load_xml(string => $string); my @nodes = $doc->findnodes('//Parent'); for my $node (@nodes) { my @childnodes = $node->childNodes or next; for my $cnode (@childnodes) { if ($cnode->nodeName =~ m/^child/) { print 'name: '. $cnode->nodeName . ', '; print 'content: '. $cnode->textContent ."\n"; } } } # Output: # name: child1, content: Child 1 # name: child2, content: Child 2 # name: child3, content: Child 3

      This works as well AjitKhodke. Again, I so appreciate your help and responses from all.

Re^2: Extract Data from XML (unique xml format?)
by clapeters (Initiate) on Jun 23, 2015 at 16:22 UTC

    Thanks so much tangent. This appears to be exactly what I'm looking for.

    I apologize for not being more clear. It made sense in my head, but not sure that's the best indicator of clarity.

Re^2: Extract Data from XML (unique xml format?)
by locked_user sundialsvc4 (Abbot) on Jun 16, 2015 at 21:52 UTC

    ++,” and, without question, this is how I would recommend doing it.

    The overwhelming-advantage of XPath is that it lets you describe, in nothing more than a simple text-string, what you want.   It’s up to the XPath engine to figure out how to do it.   The example shown performs many searches and there’s not a drop of “how” code in it.   You want such an approach, that lets you be very “what if...?” in what you search-for and subsequently plot without writing code.

      simple text string? funny