Reputation: 611
I'm relatively new to Perl, writing some XML parsing scripts. I have done two successfully, and this is my third one. I am running into issues which I think are tied to the XML document being ASCII encoded.
I am using Fedora 14 with httpd/apache/perl
I do have
use CGI::Carp qw(fatalsToBrowser);
in my web script, so I do see errors on the web page, for the most part, but for the following error, I am not seeing any error on the screen except the generic Apache "500 internal server error," and the httpd error log simply states "Premature end of script headers"
Here is the gist of the code:
my $cparser = new XML::DOM::Parser;
my $refdoc = $cparser->parse($cfile, ProtocolEncoding => 'US-ASCII');
findmynodes $refdoc;
...
sub findmynodes
{
my @refnode = $_0->findnodes("/conf:ConfModel");
...
I'm sure $_[0] OK, because if I print $_0 to a file I see "XML::DOM::Document=ARRAY(0x8bb65b8)"
I'm also sure findnodes is the culprit. Event if I do findnodes("//*") it fails.
Does anybody know what the issue could be? How can I find more info on what is failing?
Thanks,
Eric
Upvotes: 0
Views: 238
Reputation: 16161
The immediate answer: $_0
is not $_[0]
, it's the scalar variable $_0
. use strict;
would tell you that.
Also, if you can, do not use XML::DOM, XML::LibXML is more recent, better maintained, more powerful... you name it. ProtocolEncoding
is also a dangerous option, it means that you do not trust the encoding declaration in the XML. In such a case I usually check, and if necessary fix, the encoding before parsing the file. This way I have a clean, well formed XML file.
Upvotes: 3