Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

gav (2710)

  (email not shown publicly)
AOL IM: flufflegavin (Add Buddy, Send Message)

Hacker in NYC.

Journal of gav (2710)

Tuesday July 16, 2002
08:49 PM

XML hacking (take 2)

[ #6401 ]

I'm sure I already posted this at work before I left but when I got home I found I hadn't. I guess I must have forgot to hit submit or something :)

Well today I did a bit of XML hacking for the first time in a while. Usually I use XML::Simple as it is a no brainer, but this time I'm dealing with big files and I thought I it would be a good excuse to learn XML::Twig. I think mirod has done a fantastic job on this module.

Such a good job that my XML processing is basically:

use XML::Twig;
my @orders = ();

sub handle_order {
    my ($twig, $order) = @_;
    my $tax = $order->get_xpath('./Total/Line[@type="Tax"]', 0);
    if ($tax && $tax->text > 0) {
        my $addr = $order->get_xpath('./AddressInfo[@type="ship"]', 0);
        push @orders, [(map $addr->field($_), qw(Zip City State)), $tax->text];

my $twig = XML::Twig->new(TwigHandlers => { Order => \&handle_order } );

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.