NAME
XML::Saxtract - Streaming parse XML data into a result hash based upon a
specification hash
VERSION
version 1.00
SYNOPSIS
use XML::Saxtract qw(saxtract_string saxtract_uri);
my $xml = "";
my $spec = { '/root/@id' => rootId };
my $result = saxtract_string( $xml, $spec );
my $rootId = $result->{rootId};
my $complex_xml = <<'XML';
Lucas
Ali
Boo
Dude
XML
# get a map of all the employees
my $complex_spec = {
'http://def' => 'k',
'/root/k:employee' => {
name => 'employees',
type => 'map',
key => 'name',
spec => {
'' => sub {
my ($object, $value) = @_;
$object->{name} => $value;
$object->{email} => lc($value) . '@example.com';
},
'/@id' => 'id'
}
}
};
my $result = saxtract_string( $complex_xml, $complex_spec );
foreach my $employee ( keys( %{$result->{employees}} ) ) {
print( "$employee->{id}: $employee->{name} <$employee->{email}>\n" );
}
# Prints:
# 2: Ali
# 4: Dude
DESCRIPTION
This module provides methods for SAX based (streaming) parsing of XML
data into a result hash based upon a specification hash.
AUTHOR
Lucas Theisen
COPYRIGHT AND LICENSE
This software is copyright (c) 2013 by Lucas Theisen.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.