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

toolic already showed you one right way to do it ™.   So, for educational purpose only, here's an example from the dark side of XML parsing.

Sometimes this approach works, but requires that you can be really sure, that your XML is at max. one tag per line and attribute order is correct and no attribute is named TYPE and case is correct and proper quoting is used and no nested quoting occurs and ...
For each of these restrictions, there's a workaround, but you get the picture.

So this approach often works iff the producer of the XML document adheres to the contract. Then, the benefit might be a slight speed improvement.
Usually unexpected things happen many moons later.

use strict; use warnings; my $record; while ( <DATA> ) { next if /^\s*<!--/; next if /^\s*$/; $record = { TYPE => $1 }, next if /<object/ and /type="([^"] +*)"/; $record->{$1} = $2, next if /<property/ and /name="([^"] +*)"\s+value="([^"]*)"/; if ( /<\/object/ ) { # flush current record ( print join(',', map { $record->{$_} // 'n/a' } qw(name dog_breed_id dog_breed_name)),"\n" ) if $record->{TYPE} eq 'Dog'; $record = undef; # not really necessary next; } warn "Unexpected input (line $.): $_"; } __DATA__ <!-- Dog section --> <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 > <object type="Fish" > <property name="id" value="8" /> <property name="name" value="Ginger" /> <property name="status" value="alive" /> <property name="mode" value="owned" /> <property name="fish_breed_id" value="4" /> <property name="fish_breed_name" value="Guppy" /> <property name="capacity" value="105" /> <property name="size" value="big" /> <property name="location" value="glassbowl" /> </object > <object type="Dog" > <property name="id" value="9" /> <property name="name" value="Norbert" /> <property name="status" value="alive" /> <property name="mode" value="owned" /> <property name="dog_breed_id" value="7" /> <property name="dog_breed_name" value="Norwegian Wolf" /> <property name="capacity" value="105" /> <property name="size" value="big" /> <property name="location" value="norway" /> </object > <comment value="This should trigger a warning..." />

Output:

EX,0,Husky Norbert,7,Norwegian Wolf Unexpected input (line 39): <comment value="This should trigger a wa +rning..." />