What you have is not valid XML without quotes around the '4' and '5'. But you can parse like so:
use strict; use XML::Simple; use Data::Dumper; my $xml = <<EOT; <Begin> <Here ID="4">This is the start...</Here> <There REF="5">This is the middle...</There> </Begin> EOT my $xs = XML::Simple->new; my $data = $xs->XMLin($xml); print "$data->{Here}{ID}\n"; print "$data->{There}{REF}\n"; print Dumper($data);
Update: And read the docs as mirod suggests to possibly get the data structure produced more to your liking.

Its up to you whether you want to use the functional interface as mirod did, or the OO interface as I did. XMLin() calls new() when called functionally, so if you're parsing many documents in a script, its better IMO to call new() once (possibly with some options) to get a parsing object, then parse all the documents with that one object. If you're only parsing one document in a script, then you may as well use the functional interface.


In reply to Re: How can I read in XML Attributes. by runrig
in thread How can I read in XML Attributes. by basicdez

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.