Looks like the simplest way to do this might be to slurp all the data into a hash using XML::Simple then either clean up the hash or extract the data from it into another hash as is appropriate:

use strict; use warnings; use Data::Dump::Streamer; use XML::Simple; my $str = do {local $/; <DATA>}; my %data = %{XMLin ($str)}; Dump (\%data);
__DATA__ <PATIENT_DATA> <SA_PATIENT> <MY_PATIENT_ID>YYYYY</MY_PATIENT_ID> <MY_BIRTH_DATE>123-45-9876</MY_BIRTH_DATE> <MY_FIRST_NAME>FRED</MY_FIRST_NAME> <MY_GENDER>M</MY_GENDER> <MY_LAST_NAME>MUPPET</MY_LAST_NAME> <Race>Muppet</Race> </SA_PATIENT> <SA_PATIENT> <MY_PATIENT_ID>XXXXX</MY_PATIENT_ID> <MY_BIRTH_DATE>123-45-6789</MY_BIRTH_DATE> <MY_FIRST_NAME>BERT</MY_FIRST_NAME> <MY_GENDER>M</MY_GENDER> <MY_LAST_NAME>PUPPET</MY_LAST_NAME> <Address>123 SESAME ST</Address> <City>NEW YORK</City> <State>NY</State> <Zip>10110</Zip> <Race>Caucasian</Race> </SA_PATIENT> </PATIENT_DATA>

Prints:

$HASH1 = { SA_PATIENT => [ { MY_BIRTH_DATE => '123-45-9876', MY_FIRST_NAME => 'FRED', MY_GENDER => 'M', MY_LAST_NAME => 'MUPPET', MY_PATIENT_ID => 'YYYYY', Race => 'Muppet' }, { Address => '123 SESAME ST', City => 'NEW YORK', MY_BIRTH_DATE => '123-45-6789', MY_FIRST_NAME => 'BERT', MY_GENDER => 'M', MY_LAST_NAME => 'PUPPET', MY_PATIENT_ID => 'XXXXX', Race => 'Caucasian', State => 'NY', Zip => 10110 } ] };
</readme>

DWIM is Perl's answer to Gödel

In reply to Re^3: Rewriting XML::DOM based module as XML::SAX by GrandFather
in thread Rewriting XML::DOM based module as XML::SAX by Cappadonna3030

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.