2011/6/6 Dan Linder <<a href="mailto:dan@linder.org">dan@linder.org</a>>:<br>> Anyone want to throw me some additional subroutines I need to grok?<br><br>If this is something that you want or need to do with XML::Twig, then feel free to ignore the rest of this e-mail.  If you're just trying to extract the data from the XML, and you don't care how, then another option to consider is XML::XPath.  I've read lots of good things about XML::Twig, and heard great things about it from people who have used it, but I have yet to need it.  However, I have had cases where I needed to extract some data from an XML file, and the best tool I've found for simple extraction is XML::XPath.  Below is some sample code that pulls out the two bits of data you specified using XML::XPath.<br>

<br><font class="Apple-style-span" face="'courier new', monospace">#!/usr/bin/env perl<br># vim: ts=3 sw=3 et sm ai smd sc bg=dark<br>#######################################################################<br># <a href="http://xpath-test.pl">xpath-test.pl</a> - example script to show extracting data with XML::XPath<br>

#######################################################################<br><br>use 5.012; # Enable modern features.<br>use utf8;<br><br>use strict;<br>use warnings;<br>use Carp;<br>use XML::XPath;<br>use XML::XPath::XMLParser;<br>

<br># Read in our XML File.<br>my $xp = XML::XPath->new(filename => 'test-data.xml');<br><br># Try to get the start time - Note that we're not getting back a real<br># string here, we're getting back an XML::XPath::Literal with available<br>

# stringification<br>my $start_time = $xp->findvalue('/collection_status/check_starttime');<br>say "Start Time: " . $start_time;<br>croak "Couldn't get start time" unless $start_time;<br>

<br># Now we'll try to pull back our instance times<br>my $nodeset = $xp->find('/collection_status/instance/time_of_last_rate_dp');<br><br>if (my @nodelist = $nodeset->get_nodelist) {<br>   # If we got here, then there were (valid) results from our find<br>

   foreach my $node (@nodelist) {<br>      say "Instance Time: " . $node->string_value;<br>   }<br>}<br>else {<br>   croak "Couldn't find any last rate times";<br>}</font><br><br>> Dan<br><br>

-- <br>Christopher