[SOLVED] This page contains the following errors: error on line x at column y: XML declaration allowed only at the start of the document Below is a rendering of the page up to the first error.

Ever seen the error on $subject and looking for answers. Recently, I encountered the error when working with XML parsers in different browsers.

Scenario: I was seeing no issue with Firefox but with Chrome I kept getting the error shown in $subject.
Cause: After some debugging I found that this is due to the XML Parser used in chrome. After a certain query, if my result set was empty, my program was sending back and empty string (“”) back to the browser. When this is parsed for XML, Chrome threw the error shown in $subject.
Solution: If you are parsing for XML, send XML. When my result set was empty now I sent back an empty parent xml tag (i.e. <result></result>) and the problem was solved. Hope this helps anyone who comes across this issue.

2 thoughts on “[SOLVED] This page contains the following errors: error on line x at column y: XML declaration allowed only at the start of the document Below is a rendering of the page up to the first error.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s