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

Since you didn't provide your actual XML, I had to dummy some up based on the dump you provided.

<root> <Data1> <TIMESTAMP>2012-08-04T20:15:04.506-04:00</TIMESTAMP> <Data2> <DATE>2000-10-19</DATE> <ID>A95</ID> <STATUS>A</STATUS> <TIME></TIME> </Data2> </Data1> </root>

Using a slightly modified version of your script, I'm able to print the date.

use strict; use warnings; use XML::Simple; # qw(:strict); use Data::Dumper; my $simple = XML::Simple->new(); my $config = $simple->XMLin('parse3.xml'); # /home/parse3.xml isn't va +lid on my system #print Dumper( $config ); # Uncomment to get a dump of the data struct +ure print $config->{Data1}->{Data2}->{DATE}, ".\n"; __END__ Output: 2000-10-19.

Replies are listed 'Best First'.
Re^4: Perl XML parsing with XML::Simple - Having problem with accessing fields
by vparikh (Novice) on Aug 17, 2012 at 18:41 UTC
    Thank you for your answer. This is exactly what I tried and I am still not getting anything as my output. One thing I realized is the first field that I am trying to access is "DATE-NOW" and I simply changed the code to
    print $config->{Data1}->{Data2}->{DATE-NOW}, ".\n";
    I am still not getting any output. I installed this XML::Simple module yesterday on my linux and I remember when I was installing this module, it did come up as a warning that I needed XML::SAX and XML::SAX::Expat but it wasn't required and installation still was successful. Could that be the reason for this happening? I appreciate your help. Thanks a lot!

      vparikh:

      It sounds like the example data you gave us isn't the same thing as what you're running against. I'd suggest dumping the $config data structure just before printing the item of interest. That way, you'll be able to see where you're getting hung up.

      ...roboticus

      When your only tool is a hammer, all problems look like your thumb.

      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.

        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!