I think many of my family members are wondering what on earth I’m doing in the corner of a spare bedroom of my mother-in-law’s basement. It being summer and all, and having just graduated and all, and having two really fun 1 year olds and all, it is kind of crazy to be holed up. So I thought I’d take a moment to add some color to everyone’s perception of what I’m doing.
I just spent an hour trying to figure out where a newline was added to my response. I was getting this error:
XML Parsing Error: XML or text declaration not at start of entity
Location: http://
Line Number 2, Column 1:
I’m trying to make my server respond with (valid) xml, and a blank line was being added as the first line of my output. I got really close to my screen. I searched and researched every line of code. I dug through CodeIgniter’s REST base controller and scrutinized every character of the _format_xml response function that actually builds the xml. Nothing.
Then I copied an example implementation, completely gutted it, copied in my function so that the only thing in it was the function I had written, and that was presumably adding a newline at the top of the response, redirected my browser to this implementation, and … it worked. I toggled back and forth between it and the controller I had written for about 10 minutes. Could not see the difference. Finally stepped through the two files line by line and realized…
any white space outside of the tags is part of the response!!!
Don’t forget that. I had an empty line in my controller php file at the very end, after the closing php tag. That line became the first line in my response, and my formatted xml came after that. So the browser interpreted the sum as invalid xml.
These are the adventures of a Microsoft developer in LAMPLand.