If you actually ran the code you posted, you would know what was wrong.
syntax error at ./parse.pl line 13, near ") #" You lost the semicolon. It should be: print Dumper($config); # this prints out parsed xml
Once that's fixed you'll encounter two more errors: Bareword "DATE" not allowed while "strict subs" in use at ./parse.pl line 13. Bareword "NOW" not allowed while "strict subs" in use at ./parse.pl line 13.
Quote DATE-NOW: print $config->{DATA1}->{DATA2}->{'DATE-NOW'}, ".\n";
Now you'll see there are problems with the XML.. End tag mismatch (DATA1 != TIME) [Ln: 10, Col: 9] I'm assuming you typed it instead of using copy/paste. Here's the corrected XML:
<DATA> <DATA1> <TIME>2012-08-04T20:15:04.506-04:00</TIME> <DATA2> <DATE-NOW>2000-10-19</DATE-NOW> <ID>A95</ID> <STATUS>A</STATUS> <TIME/> </DATA2> </DATA1> </DATA>
Here's the code with the above corrections made:
use strict; use warnings; use XML::Simple; # qw(:strict); use Data::Dumper; my $simple = XML::Simple->new(); my $config = $simple->XMLin('parse3.xml'); print Dumper($config); # this prints out parsed xml print $config->{DATA1}->{DATA2}->{'DATE-NOW'}, ".\n";
In reply to Re^7: Perl XML parsing with XML::Simple - Having problem with accessing fields
by Mr. Muskrat
in thread Perl XML parsing with XML::Simple - Having problem with accessing fields
by vparikh
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |