Sunday, February 22, 2009

Bad Xml – to accept or to reject, that is the question.

Was just reading this post which touches on accepting invalid Xml communications. And I agree.

I think it boils down to “make sure you produce good XML, but accept anything with the proviso that there may be odd behaviour if the format is not correct”. Library wise though, permissive reading is fine, but if your library produces bad XML you deserve to be stamped out. I have to say that the Microsoft Xml stuff is really pretty good. They are an option 1 library though, so don’t expect to be able to read in any old just, but they will not produce invalid Xml*.

This is the route that I have gone with all of the stuff that I have been doing lately. It is a little more complicated than that though because the data structure that I am using is created from the DTD** so I need to not only accept invalid XML but convert it into valid XML to store it.


* This is something that I have had to explain a few times… Sometimes is is difficult, sometimes people understand. Mostly I don’t bother complaining too much about receiving nasty Xml, but forcing myself to produce bad Xml because someone’s hand coded parser reacts badly to something valid in my valid Xml (namespace definition).

** Funny story. It’s their DTD, but they can’t manage to produce Xml that validates against it, and they expect values for certain elements that are not valid under it (value="" when value is an NMTOKEN). Chuckle…

No comments:

Post a Comment