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..." />


In reply to Re: XML::Parser using stream by Perlbotics
in thread Solved: XML::Parser using stream (used XML:Rules) by Falantar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.