Hi, I am still pretty bad at regular expressions and could use some help parsing out an XML file using regular expressions (though if there are other ways of getting data from the XML file, I am all ears; though I would prefer not to install a new perl module in doing so). I have an XML file that look something like this: <more>
<EVENT> <NAME>test2</NAME> <LOCATION>iwu</LOCATION> <TIME>now</TIME> <DATE>today</DATE> <PRIORITY>interest</PRIORITY> <ATTENDEES>a lot</ATTENDEES> <DESCRIPTION> descrip</DESCRIPTION> </EVENT> <EVENT> <NAME>test3</NAME> <LOCATION>hi</LOCATION> <TIME>joe</TIME> <DATE>how</DATE> <PRIORITY>interest</PRIORITY> <ATTENDEES>are</ATTENDEES> <DESCRIPTION> </DESCRIPTION> </EVENT>
I would like to count how many events are in the file and store the information about each event into a two dimensional array (or something like that). Here are my thoughts. This regex
$variable =~ s/<EVENT>.*?<\/EVENT>//gi;
,from what I understand, will place the place the text between the EVENT tags into a variable. However, I'm not sure what will happen if I have more than one set of EVENT tags such as in the XML above. I would like to isolate each event (and I want to have an indefinite number of events) into a separate array element. Then I can begin splitting up the data for each event into variables somehow. Does anyone have any ideas on how to do this. I would be very grateful for any help that you could offer me. Thanks for taking the time to read this. Joe Added: Forgive me, the above regex should look something more like this
if ($page_body =~ /.*?<EVENT>(.*?)<\/EVENT>.*?/) { $variable = $1; }
</more>

In reply to XML Parsing by JoeJaz

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.