2007.10.23

Solving MIME type headaches 2007-10-23T10:09:38ZTitled entry permalink

My site occasionally serves invalid XML. This is an unfortunate business. The reasons are quite convoluted, but are to do with the way that you can't use CDATA sections inside attributes (Kosso will understand what I'm talking about).

So sometimes unencoded stuff is sent to the browser, or, as this morning, an unclosed span element.

I decided to fix it by writing some code that would detect whether what's about to be sent is valid XML. Simple enough. Just load it all into a DOM tree, and if it chokes on loading, it's not valid XML - then serve it as text/html to invoke the usually slower XHTML parsers.

Here's the code. It's done with PHP output control and the DOM - so PHP5 only, folks. You do use PHP5, right?

Links from del.icio.us

 

Login with your OpenID:
No. 690
Tom Morris
Currently in: Greater London, England
Usually in: East Sussex, United Kingdom
AIM: tommorris
YIM: tom.morris

I am a , an , like to code in and noodle about with and the . I also have a BA in philosophy from London, and am in preparation for an MA. My philosophical interests are in Victorian-era German philosophy, Kierkegaard, Robert Nozick, hermeneutics and current approaches to the demarcation problem in the philosophy of science. Musically, I like jazz fusion, soul and P-Funk. My musical nirvana would be a mixture of Beethoven, Miles Davis and George Clinton topped with a side-serving of Erykah, Jill and Angie.

Elsewhere:

  • GPG Key
  • del.icio.us
  • Flickr
  • Twitter
  • digg
  • Jaiku
  • LinkedIn
  • ma.gnolia
  • blip.tv
  • upcoming.org
  • MetaFilter
  • LiveJournal
  • CiteULike
  • Technorati Profile

RSS Feed Subscribe:

RDF

« October 2007 »
SuMoTuWeThFrSa
 123456
78910111213
14151617181920
21222324252627
28293031 

View in month context

On this day in: 2006