Hey!
I wondered why one of our sites didn’t validate although the xhtml was valid.
I always got the error:
line 1 - Error: character "" not allowed in prolog
When using the source view from firefox there wasn’t any character in front of the
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
After debugging into this issue I realized that these errors occure when
- the cache has been cleared
- your lexicon *.inc.php files are UTF-8 encoded
- you switch the topic within your page e.g. something like ... [[%test? namespace=`mysite` &topic=`default`]].... [[%other? namespace=`mysite` &topic=`other`]]...
Ok if all these requirements are satisfied the UTF-8 invisible characters are printed in front of the page’s content. By switching the encoding in Firefox’s sourcecode browser to Latin these characters are visible:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
After requesting the page again (now it’s in the cache) these characters are not present any more.
I was able to fix this problem by using "UTF-8 without POM" encoding for my lexicon files.
Here is how I was able to reproduce the eror using modx 2.0.6-pl, NotePad++ on Windows 7, with xampp 1.7.3:
1. setup a new namespace ’mysite’
2. create two lexicon files (topics) which are UTF-8 encoded in the components ’en’ folder:
<?php
$_lang['test'] = 'TestEN';
<?php
$_lang['other'] = 'otherEN';
3. Set the BaseTemplate to
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<base href="[[++site_url]]" />
<title>[[++site_name]] - [[*pagetitle]]</title>
</head>
<body>
<div>
<h1>Test</h1>
<div>
[[*content]]
</div>
</div>
</body>
</html>
4. Set the Home page’s content to
<p>[[%other? namespace=`mysite` &topic=`other`]]</p>
<p>[[%test? namespace=`mysite` &topic=`default`]]</p>
5. Clear the cache
6. Open the Home page: The ’Test’ heading is not on top of the page (because of the strange UTF-8 characters)
7. Open it again (after being cached): The ’Test’ heading is on top of the page
Can any one confirm this issue? Or am I missing something?
Cheers,
Jakob