in reply to XML Parsing
As for the code you posted you need to add the /s modifier or the .'s will not match the newline characters (will not cross over lines). If it were me and was doing a quick hack I would probably still use XML::Simple, but as for changing your regex to capture multiple matches you might try something like the following:use strict; use warnings; use XML::Simple; use Data::Dumper; my $string = do { local $/; <DATA>}; my $ref = XMLin($string); print Dumper $ref; my $num_events = @{$ref->{EVENT}}; print "There are $num_events events listed\n"; __DATA__ <ROOT> <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> </ROOT>
Also note that it is pointless to have .*? at the very start of a regular expression as it will cause a lot of of needless backtracking, and never really match anything, as a regex looks for a pattern anywhere in the string (lest it be anchored)my @events; while ($page_body =~ /<EVENT>(.*?)<\/EVENT>/sg){ push @events, $1 #note $1 might have zero length. }
-enlil
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
2Re: XML Parsing
by jeffa (Bishop) on Apr 24, 2004 at 14:12 UTC | |
|
Re: Re: XML Parsing
by JoeJaz (Monk) on Apr 24, 2004 at 10:55 UTC |