in reply to Couldn’t create file parser context for file "somename.xml"

No such file or directory. means you are attempting to open/parse a file that doesn't exists.

Make sure you've got the right file name before attempting to parse it. Something like this might help

# inside your foreach loop before parsing, check if the file does exis +ts if (-e $file ) { # parse the file }else{ print "$file doesn't exists\n"; }

Replies are listed 'Best First'.
Re^2: Couldn’t create file parser context for file "somename.xml"
by laleh-poly (Novice) on Dec 31, 2009 at 18:12 UTC
    Thanks Ahmad, But both files exist. I deleted the file (the copied one) from the directory and run my script, every thing was fine, then I make a copy of this file and just changed its name (at this point two files are now in the directory). When i run the script for the second time, for the original file it works, but for the copied one, I get the error. But if i repeat the above process it works for both files. For every new file that I add to the directory it does not work for the first time but when I delete the file run the script, then again move the file to the directory it works!!! so wired.

      I bet you do something silly like `ls` and you don't properly extract the line feeds.

      Place the following just before the code you posted:

      use Cwd; use Data::Dumper; print("cwd = ", getcwd(), "\n"); print("files:\n", do { local $Data::Dumper::Useqq = 1; Dumper(\@files); });

      What do you get?

        Hello, After adding the code proposed I get the following:
        $ perl parseXML.pl "D:\Perl-Implementaion\ParseXM L\test" cwd = /cygdrive/D/Perl-Implementaion/ParseXML files: $VAR1 = [ "bb.xml", "bbCopy.xml" ]; bb.xml className= org.argouml.uml.cognitive.critics.CrClassMustBeAbstract methodName= predicate2(Object,Designer) bbCopy.xml Could not create file parser context for file "bbCopy.xml": No such fi +le or dire ctory at parseXML.pl line 37
        You see both files are there. By the way I do not "ls". To get the files in a directory I have the following in the beginning of my script:
        use XML::LibXML; $ARGV[0] || die; $path=$ARGV[0]; # open the designated directory opendir(DIR, $path); @files = grep(/\.xml$/,readdir(DIR));
        Thanks for helping me.