Can't read from xml file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SandeepShanu
    New Member
    • Aug 2010
    • 1

    #1

    Can't read from xml file

    Hi,

    I want to store an xml file in a var so that i can use the particular values of some nodes later.
    i am using following code:

    Code:
    #!C:\Perl\bin
    
    use XML::Simple;
    use Data::Dumper;
    
    $xml = new XML::Simple;
    $data = $xml->XMLin('cas.xml');
    print Dumper($data);
    But its giving error:
    "File does not exist: cas.xml at xml_test.cgi line 7"

    I have kept both code file & xml file at same place.
    I also tried giving the absolute path "C:\test\cas.xm l".

    But its throwing same error.

    Kindly Help.

    Regards,
    Sandeep
    Last edited by numberwhun; Aug 19 '10, 12:08 AM. Reason: Please Use CODE TAGS!
  • RonB
    Recognized Expert Contributor
    • Jun 2009
    • 589

    #2
    Always use the code tags when posting code.

    Always use the strict and warnings pragmas and declare your vars with the 'my' keyword.

    Double check the spelling of the filename and path.

    When using the absolute path, use forward slashes instead of backslashes.

    Code:
    #!C:\Perl\bin
    
    use strict;
    use warnings;
    use XML::Simple;
    use Data::Dumper;
    
    my $xml = XML::Simple->new;
    my $data = $xml->XMLin('C:/test/cas.xml');
    print Dumper($data);

    Comment

    Working...