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

Fellow Monks,
I had a cgi script that was working yesterday, but today its broken. Nothing changed in the script. I'm running activestate perl, so I'm guessing that some modules got automatically overwritten (does this happen? could some monk confirm this). The error message I'm receiving is along the lines of:
Internal Server Error: [Wed Apr 7 10:13:33 2004] QASearch.cgi: [Wed Ap +r 7 10:13:33 2004] QASearch.cgi: junk after document element at line +45, column 0, byte 1010 at C:/Perl/site/lib/XML/Parser.pm line 187
My script does not use XML::Parser.pm, but it does use XML::Simple so I'm guessing this is where the problem lays. If anybody has any ideas on how to fix this problem could they please let me know.

Thanks in advance,
Jonathan.

Replies are listed 'Best First'.
Re: broken cgi script
by Corion (Patriarch) on Apr 07, 2004 at 09:35 UTC

    The problem is within your XML document, or at least that's what the error message tells me. After some element in line 45, column 0 in your XML document, there is something that doesn't make sense to XML::Parser.

    Look at that location and fix whatever changed there.

    Perl does not overwrite modules of its own, but if you upgrade your modules, the modules' behaviour can change between versions.

Re: broken cgi script
by borisz (Canon) on Apr 07, 2004 at 09:35 UTC
    I guess the input xmlfile is broken somehow. Look into the file around line 45 for chars that are not part of your encoding. Delete the chars, or translate them. And retry.
    Boris
      D'oh, I've been trying to solve this for about an hour, and that never occurred to me. Thanks for the suggestions, you are both correct! everything working fine now...

      Jonathan

Re: broken cgi script
by mirod (Canon) on Apr 07, 2004 at 09:49 UTC

    The error message tells all: there is something the parser does not recognise after the end of the XML document. An XML document contains only one root element, after that element is closed you can't have anything except syntactic constructs that don't impact the document tree: whitespaces, comments or processing instructions. Other elements or non-whitespace characters are forbidden. You can use a parser (or just XML::Parser with perl -MXML::Parser -e'XML::Parser->new( ErrorContext => 1)->parsefile( "file.xml")' to check the XML.

Re: broken cgi script
by blue_cowdawg (Monsignor) on Apr 07, 2004 at 14:56 UTC

        If anybody has any ideas on how to fix this problem could they please let me know.

    Well Johnathan,
    Lots of monks have already chimed in on this with the right answer, but let me add some thoughts anyway.

    Always, always, always, have some validation methods available to you. In this case I would have had some XML that I know works to validate that it still works.

    If you have a test suite available to you that you've developed then you can be more confident in your code.

    You didn't post any code so I can't tell if you did anything to catch errors to avoid the Error 500 Internal Server Error bomb. Of course the crystal ball doesn't always tell you ahead of time all the wonderful ways users can break your code.