Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^5: Perl XML parsing with XML::Simple - Having problem with accessing fields

by Mr. Muskrat (Abbot)
on Aug 17, 2012 at 19:01 UTC ( #988072=note: print w/ replies, xml ) Need Help??


in reply to Re^4: Perl XML parsing with XML::Simple - Having problem with accessing fields
in thread Perl XML parsing with XML::Simple - Having problem with accessing fields

Apparently, the XML doesn't match up to the dump you provided. Add the following before the line where you are trying to print the date so that you can see what the parser thinks the XML looks like.

print Dumper( $config );

If you still can't figure it out, provide the XML from /home/parse3.xml.


Comment on Re^5: Perl XML parsing with XML::Simple - Having problem with accessing fields
Download Code
Re^6: Perl XML parsing with XML::Simple - Having problem with accessing fields
by vparikh (Novice) on Aug 17, 2012 at 19:39 UTC
    Sorry if this is causing the confusion. Alright so I am providing everything again. This is my original XML file:
    <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>
    And this is my perl script: My goal is to get to - 2000-10-19
    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";
    Please let me know what I can change in my code to make it work.
    Thanks everyone again! You have all been a great help!

      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";

        It works!! Thanks a lot for your helps.. I was really lost on what I did wrong but it is working thanks to you!! I really appreciate it!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://988072]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2014-12-26 15:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (171 votes), past polls