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

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.
  • Comment on Re^2: Couldn’t create file parser context for file "somename.xml"

Replies are listed 'Best First'.
Re^3: Couldn't create file parser context for file "somename.xml"
by ikegami (Patriarch) on Dec 31, 2009 at 19:02 UTC

    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.
        You're telling XML::Parser to open
        /cygdrive/D/Perl-Implementaion/ParseXML/bb.xml
        and
        /cygdrive/D/Perl-Implementaion/ParseXML/bbCopy.xml

        but the files you want to open are
        D:\Perl-Implementaion\ParseXML\test\bb.xml
        and
        D:\Perl-Implementaion\ParseXML\test\bbCopy.xml

        Notice the missing "test". Fix:

        my @files = map "$path/$_", grep /\.xml\z/, readdir(DIR);