Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re^3: Fetch field values from API output

by roboticus (Chancellor)
on Dec 13, 2012 at 18:32 UTC ( #1008700=note: print w/ replies, xml ) Need Help??

in reply to Re^2: Fetch field values from API output
in thread Fetch field values from API output


In that case, I'd look into using XML::Twig to parse your XML document(s). Looking at it, it seems like the code should be pretty simple. I've not used it before, so I'm sure I'll get some details wrong, but I would think that something like this could do it:

#!/usr/bin/perl use strict; use warnings; use XML::Twig; use Data::Dump; my @work_items; # Set up the parser my $twig = XML::Twig->new( twig_handlers => { usageAccum => \&gather_values, } } # Parse the file and gather work items $twig_parsefile('foo.xml'); # Process the work items for my $r (@work_items) { print Dumper($r), "\n"; } sub gather_values { # We just got a usageAccum node, so get the interesting attributes # and push them into the work item list. my $node = shift; push @work_items, { inclUnits => $node->{attr}->{inclUnits}; inclUnitsUsed => $node->{attr}->{inclUnitsUsed}; shared => $node->{attr}->{shared}; }; }

I didn't test it, as I'm busy at the moment. But you should be able to turn this into something useful. If you have trouble, hopefully we can get an XML::Twig savvy monk to chime in with tips.


When your only tool is a hammer, all problems look like your thumb.

Comment on Re^3: Fetch field values from API output
Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1008700]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2015-11-29 15:32 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (751 votes), past polls