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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|