Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

XML::LibXML - could not create file parser context : no error

by rbala (Acolyte)
on Nov 15, 2013 at 12:45 UTC ( #1062735=perlquestion: print w/ replies, xml ) Need Help??
rbala has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am getting a strange(?!) issue, while parsing and xml file using XML::LibXML. Below is my code :
my $parser_obj = XML::LibXML->new(); my $doc; my $xml_file = "filename.xml"; $doc = $parser_obj->parse_file($xml_file); my ($xml_node) = $doc->findnodes($xpath);

The error lies in line 3 , where I get the error as ,"Execution Failed: Could not create file parser context for file "filename.xml" No error at line 3 <filename.pm>

I am getting this error when I do this operation for a repeated number of times, and also the file is always existent in the specified location. The worst part is , I could not figure out, when this error occurs. Some times, it occurs in 6th iteration, sometimes in 100th iteration. Does it has anything to do with the file access issues by XML::LibXML ? Please advise.

Thanks, Bala.

Comment on XML::LibXML - could not create file parser context : no error
Download Code
Re: XML::LibXML - could not create file parser context : no error
by hippo (Curate) on Nov 15, 2013 at 13:13 UTC

    It's only a guess but since you mention "iteration" and don't show any, there's a reasonable chance that the problem is related to how you are performing this "iteration". If you can post a complete, small self-contained script, together with sample input data which demonstrates the problem it might then be possible to see precisely where the problem lies.

      Hi Hippo, You can assume it to a function happening at regular intervals like the below :
      sub parsexml { my $parser_obj = XML::LibXML->new(); my $doc; my $xml_file = "filename.xml"; $doc = $parser_obj->parse_file($xml_file); my ($xml_node) = $doc->findnodes($xpath); } parsexml(); sleep 30; parsexml(); sleep 30; . . . .
      The overall thing happening is , same file is accessed multiple times or parsed multiple times this way over a period of time. I am not sure, if the problems lies here or not. Please revert if more details are required. Thanks, Bala.
        Problem is somewhere else, I would say, as the following works for me without problem:
        for (1 .. 10000) { my $p = 'XML::LibXML'->new; my $d = $p->parse_file('example.xml'); my $n = $d->findnodes('/'); }

        Does any other process overwrite the file at the same time?

        لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: XML::LibXML - could not create file parser context : no error
by tobyink (Abbot) on Nov 15, 2013 at 14:00 UTC

    Is the file local, or on a network device?

    use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
      File is local only!

Log In?
Username:
Password:

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

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

    How do you remember the number of days in each month?











    Results (138 votes), past polls