xml parsing error

xml parsing error

by Peter Postma -
Number of replies: 2
I have run into a problem with developing a block.

I am using moodle 1.8 and created a block. The block installs fine, but when I add block to the layout I get this error:

XML Parsing Error: xml declaration not at start of external entity
Location: http://localhost/moodle/index.php
Line Number 2, Column 1:

<?xml version='1.0' encoding='utf-8'?>

No matter what changes I make or corrections I try it continues to do that. Once it is added no one can use moodle until I delete the block references from the database manually.

I copied the step by step Guide to Creating Blocks and made the simplehtml block exactly as stated, same error on that one. If you open the Admin's Modules->blocks page (after installing the block) in a separate window when you add it to the layout, cause the error, and then click delete simplehtml block in the separate window, you get a different XML parsing error (it does successfully remove it, but not from the block instances table)

I tried to grep the moodle code files, and a dump of the database and found no XML or other files that do not have the XML declaration as the first line. The only occurance of a single quote, lowercase | encoding='utf-8' | in the code occurs in lib/weblib.php:2298 under force_strict_header

Since this was not a problem before before I add the block (and force_strict_header is used for every page) what would cause this problem?? I'm not sure how to make the debug code print out Line Number 1 to see what is there because I don't even know where it is happening in the code.

Does anyone know what this problem is, or even where it happens so I can force it to print more debugging information?

Peter

p.s. The goal of the block is to embed a JavaApplet bitmap editor that contains a save function.
Average of ratings: -
In reply to Peter Postma

Re: xml parsing error

by Peter Postma -
I solved the problem. There is an unspoken rule in building blocks, there can be NO whitespace outside of the PHP tags!!

so if this is your file:
---------------------
|<? |
| ... |
|?> |
---------------------

You cannot do this:

---------------------
|<? |
| ... |
|?> |
| |
---------------------


That extra line prints out at the top of the page dropping the
<?xml version='1.0' encoding='utf-8'?>
down a line and causing a problem on the browser's side. Only some browsers report this error. It really depends on the server and the browser whether this error is thrown.

Peter
In reply to Peter Postma

Re: xml parsing error

by William Goedicke -
We're new to moodle at my institution and I'm curious about one thing. When you say "I solved the problem" does that mean you've edited a fix into the php on your site to make this error stop occuring, or do you mean that you've created a patch and entered it into the current build in CVS.

I don't want that to sound like I'm putting you on the spot. Rather, I'm trying to get a sense of how community members deal with bugs.

- Billy