in reply to Solved: XML::Parser using stream (used XML:Rules)

Another option is XML::Rules:
use strict; use warnings; use XML::Rules; use Data::Dumper qw(Dumper); my $xml = <<XML; <object type="Dog" > <property name="id" value="0" /> <property name="name" value="REX" /> <property name="status" value="alive" /> <property name="mode" value="owned" /> <property name="dog_breed_id" value="0" /> <property name="dog_breed_name" value="Husky" /> <property name="capacity" value="105" /> <property name="size" value="big" /> <property name="location" value="canada" /> </object > XML my @rules = ( "^object" => sub { $_[1]{type} eq 'Dog' }, object => sub { print join("|", @{$_[1]}{qw(name dog_breed_id dog_breed_name)}),"\ +n"; return; }, property => sub {$_[1]->{name} => $_[1]->{value}}, ); my $xr = XML::Rules->new( rules => \@rules, stripspaces => 2 ); $xr->parse($xml);

Replies are listed 'Best First'.
Re^2: XML::Parser using stream
by Falantar (Initiate) on Aug 18, 2011 at 11:52 UTC
    That is excellent. Seems like a great parser, wonder why I haven't heard of it before! Quick and I don't get a segfault either. Now I just need to make the script stop once all of the info has been processed. Since it's all together in the same group, it doesn't have to keep analyzing the rest of the file.