Invalid XML declaration

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Invalid XML declaration

Postby madfiddler » 12. October 2009 23:54

Hi all.

New around here but been using xampp for a while locally on my pc to test web site dev

I have an install of SMF I am working on (simple machines forum) with tiny portal and the SMF Media Gallery

I have a slideshow add-on for the gallery which uses an XML feed produced via Ajax I believe

the problem I am having is that a blank line (or rather single carriage return and line feed charactes) are being placed at the start of the XML in my local setup and it causes an error when parsing the XML since the XML declaration is not on the first line.

running this on my web hosts test site it seems fine. It's only xampp running locally that seems to do this.

I am running the standard 1.7.2 package And have not modified it
I am assuming there is something in th xampp config causing this issue

anyone got any ideas?

Thanks in advance
mf
madfiddler
 
Posts: 7
Joined: 12. October 2009 23:43

Re: Invalid XML declaration

Postby Izzy » 13. October 2009 00:26

I use XML and AJAX on various mobi and static web sites I develop on different versions of XAMPP without this issue - so this is not perhaps XAMPP related but more like your script.

Your hosting server may well use Linux and they may also have short open tags set to On for backward compatibility issues.

So make sure that the php open tags in your scripts looks like this:
<? php and ?>

not like this:
<? and ?>

Here is the relevant section in the php.ini file in XAMPP 1.7.2
php.ini file wrote:; This directive determines whether or not PHP will recognize code between
; <? and ?> tags as PHP source which should be processed as such. It's been
; recommended for several years that you not use the short tag "short cut" and
; instead to use the full <?php and ?> tag combination. With the wide spread use
; of XML and use of these tags by other languages, the server can become easily
; confused and end up parsing the wrong code in the wrong context. But because
; this short cut has been a feature for such a long time, it's currently still
; supported for backwards compatibility, but we recommend you don't use them.
; Default Value: On
; Development Value: Off
; Production Value: Off
; http://php.net/short-open-tag
short_open_tag = Off
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06

Re: Invalid XML declaration

Postby madfiddler » 13. October 2009 23:10

thanks for the suggestion


that sounded really promising but did not seem to make any different whatsoever whne I set this option on - I mad sure I cleared my browser cachae and restarted apache to no avail

I also did a global search through all the php scripts for the tags you mentioned in fact I did a search for <? rather than <?php

I found no occurrence of <? on its own only <?php and <?xml

any more thoughts anyone?
madfiddler
 
Posts: 7
Joined: 12. October 2009 23:43

Re: Invalid XML declaration

Postby madfiddler » 13. October 2009 23:45

ahhhhh....


ok I've now realised this is not specifically an XML issue - every page on my localhost has a blank line at the start if I view the source doe in my browser
on my web host this is not the case

does that shed any more light on things?...
madfiddler
 
Posts: 7
Joined: 12. October 2009 23:43

Re: Invalid XML declaration

Postby Izzy » 14. October 2009 00:06

Are you using UTF-8 encoding which can add a BOM (Byte Order Mark) on the first line?

For more info on BOM and help to remove it, take a look at these search results.
http://www.google.com/search?q=how+to+remove+bom
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06

Re: Invalid XML declaration

Postby madfiddler » 14. October 2009 00:38

don't think that's the issue

when I view the source code in the browser, save it and then open it in a hex editor I can quite clearly see a carriage return line feed combo as the first two bytes (x'0D' x'0A')

if BOM had been the problem I would have expected to see that in the source of pages saved from my local xampp install instead
and I would have thought I would see the same thing from my actual web host/server too, but I don't

this is really starting to bug me now!.....I guess when I finally find out what is causing this it will bound to be something simple :|
madfiddler
 
Posts: 7
Joined: 12. October 2009 23:43

Re: Invalid XML declaration

Postby Izzy » 14. October 2009 00:56

XAMPP does not write anything to any of your files in the htdocs folder, so we can eliminate XAMPP as a source of these additions.


Can you check using your hex ed other files that you have downloaded to your PC, other than those you already know about in XAMPP, especially ASCII type downloads or those defined in your down loader as ASCII in the Auto setting.

My theory is that this may be related to how you are downloading/uploading files ie. in ASCII or Binary or even in Auto mode in the app you use to download files form the net.

ASCII mode may add characters when downloading/uploading where as binary usually mirrors the actual file contents when downloading/uploading.

As a general rule and to save having this annoying issue again, perhaps consider downloading all files in binary mode to get a matching pair of files - check the bytes and they should be the same at both locations ie at the source and destination, ASCII may have slightly more bytes after downloading or uploading than the original file where binary mode will have identical bytes.


If it's any consolation I have just downloaded using binary mode and installed what I believe to be your scenario of SMF files and addons to 1.7.2 and have no issues at all.
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06

Re: Invalid XML declaration

Postby madfiddler » 14. October 2009 10:26

hi

I've been working on this for a while therefore it is a little difficult for me to determine what method I have used to download from my web host to my local xampp setup

However I THINK you're right with your last idea

Some files I've downloaded using WinSCP (FTP client) and some I will have downloaded directly from my CPANEL - I don't think I used any other methods

When I first started comparing the files on the live host compared to my local setup I could see that the vast majority are the same size...but then I started to notice differences and could see carriage return line feeds at the end of my files that I have locally.

Looking into this more it appears that some files are full of those characters x'0D' x'0A' for "new line" whereas the ones on my host are c'0A' only

I have been able to reproduce this by using WinSCP with the "default" trasnfer method, switching to binary mode the files arrive on my PC "as is"

I use the text editor PSPad and this seems to go along with whatever I download...so if it thinks its unix it sticks with x'0A' only as I'm editing (which is a good thing!)


So now all I need to do is find a dos2unix converter for windows and let it go through all my files

thanks
mf
madfiddler
 
Posts: 7
Joined: 12. October 2009 23:43

Re: Invalid XML declaration

Postby madfiddler » 14. October 2009 10:55

I downloaded dos2unix from here
http://www.bastet.com/

and then this command I ran from the command line in the htdocs folder
Code: Select all
FOR /F "tokens=*" %G IN ('DIR /B /S /A-D *.php *.txt *.css *.xml *.html *.js *.*~') DO dos2unix %G



seems to have sorted it all out for me :)

thanks for your assistance
madfiddler
 
Posts: 7
Joined: 12. October 2009 23:43


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 155 guests