Here's your first example, rewritten to use XML::LibXML...
use 5.010; use strict; use XML::LibXML 1.94; my $xml = XML::LibXML->load_xml(location => 'input.xml'); foreach my $thing ($xml->findnodes('//thing')) { # The difference between findnodes and findvalues is this: # findnodes returns a list of matching XML::LibXML::Node objects; # findvalue returns the first matching string (well, an object # that overloads stringification anyway). So here we use the # latter... # my $unique_id = $thing->findvalue('./unique_identifier'); say "==== ", $unique_id; foreach my $foo ($thing->findnodes('./foos/foo')) { my $foo_datum = $foo->findvalue('./foo_datum'); say "foo_datum: ", $foo_datum; } foreach my $bar ($thing->findnodes('./bars/bar')) { my $bar_number = $bar->findvalue('./bar_number'); my $good_info = $bar->findvalue('./good/good_info'); say "bar: ", $bar_number, ", good info: ", $good_info; } }
In reply to Re: I (Think I) Need to Break Up with XML::Simple and I Don't Know Where to Turn
by tobyink
in thread I (Think I) Need to Break Up with XML::Simple and I Don't Know Where to Turn
by Randomice
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |