开发者

Perl XML::DOM issues with ASCII XML?

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 issu开发者_运维技巧e could be? How can I find more info on what is failing?

Thanks,

Eric


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜