blink has asked for the wisdom of the Perl Monks concerning the following question:

I've heard anecdotal evidence about the fact that certain Perl CGI scripts running fine under Netscape/Mozilla, but not on IE.

Here's the error I get, followed by the code itself:

The XML page cannot be displayed Cannot view XML input using XSL style sheet. Please correct the error +and then click the Refresh button, or try again later. Only one top level element is allowed in an XML document. Error proces +sing resource 'http://bkup1/cgi-bin/get-sched.cgi'. Line 1, Position +45 <h1>NBU Backup Schedule Retrieval Tool</h1><p>Choose a backup client f +rom the pulldown menu and push 'get my schedule' to retrieve all acti +ve backup schedules for your chosen server</p><hr /><?xml version="1. +0" encoding="utf-8"?> --------------------------------------------^

The Code

#!/opt/openv/perl/bin/perl -w use strict; use NBUX; use CGI; use CGI::Carp qw/fatalsToBrowser/; my %data; my $sid; my $day; my @clients; my %bpclients = bpclclients(); foreach (sort keys %bpclients) { push @clients, $_; } my $query = new CGI; print $query->header, $query->h1("NBU Backup Schedule Retrieval Tool"), $query->p( 'Choose a backup client from the pulldown menu and pus +h \'get my schedule\' to retrieve all active backup schedules for you +r chosen server' ), $query->hr, $query->start_html( {-bgcolor=>'#CCFFCC'},'NBU Sch +edule Getter'), $query->startform, $query->popup_menu( -name => 'backup client', -values => [@clients], -default => '' ), $query->submit('Action', 'get my schedule'), $query->endform; get_schedule($query->param('backup client')); print $query->end_html; sub get_schedule { my ($client) = @_; my $cmd = "/opt/openv/netbackup/bin/admincmd/bppllist -byclient $c +lient -U"; open CMD, " $cmd |" or die "Cannot run $cmd: $@\n"; while (<CMD>) { next if (/Default/); if (/Policy Name:(\s+)(.*?)$/) { $sid = "$2"; next; } next unless (/(\s+)Daily Windows\:/ .. /(\s+)Schedule\:/); if (/(^\s+)(.*?day)/) { next if (/24|Week/); $day = $_; chomp $day; push @{$data{$sid}}, $day; } } foreach my $key (sort keys %data) { print $query->br, $query->b("$key starts between"); foreach (@{$data{$key}}) { print $query->pre("$_"),; } print "======================================================= +====="; } }

Replies are listed 'Best First'.
Re: CGI.pm, XML and Internet Explorer
by sauoq (Abbot) on Jul 30, 2003 at 18:33 UTC

    The error you are getting makes it look like your script is printing some things out in a funky order... Someone else was having a similar problem the other day. The answer in that case was to turn autoflush on. That's usually a good idea in CGI scripts anyway and doing so just might correct the problem you are having. Put

    $| = 1;
    somewhere near the top of your script and see if that fixes things.

    After taking a closer look, it seems you might be able to correct it by using a separate print statement to print the header. In other words,

    print $query->header; print $query->h1( ... ), $query->p( ... ); # Etc... # instead of # print $query-header, $query->h1( ... ), $query->p( ... );
    I still recommend turning autoflush on though.

    -sauoq
    "My two cents aren't worth a dime.";
    
Re: CGI.pm, XML and Internet Explorer
by CountZero (Bishop) on Jul 30, 2003 at 18:33 UTC

    You cannot output <?xml version="1.0" encoding="utf-8"?> unless at the very beginning of your webpage. Perhaps Netscape and Mozilla will correct such error, but an XML-document which does not start with this invocation is incorrect XML.

    This of course does not solve your problem and I'm at a loss to find a solution as I do not see from your code where this top-level XML-item comes from.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re: CGI.pm, XML and Internet Explorer
by PodMaster (Abbot) on Jul 31, 2003 at 06:15 UTC
    From the CGI.pm docs
    -no_xhtml

    By default, CGI.pm versions 2.69 and higher emit XHTML (http://www.w3.org/TR/xhtml1/). The -no_xhtml pragma disables this feature.

    Unless you want to learn about xhtml, I suggest you use that pragma.

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.