Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Perl Monk, Perl Meditation
 
PerlMonks  

Re^3: Fetch field values from API output

by roboticus (Canon)
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

rkrish:

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.

...roboticus

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2014-04-18 08:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (464 votes), past polls