Like just about all software developers these days, I’ve done my fair share of XML wrangling. What I hadn’t done until this week is create DTDs or schemas to describe the XML I was generating. Then I ventured into the realm of XML schemas, and I have to say that I come away impressed. The schemas themselves are easier than you might thing to write, and there are a number of cool schema tools out there. My favorite is Microsoft’s XSD Inference Demo, which creates a valid schema for an XML document for you. Unless your format is very rigid, you’ll have to edit the schema that it produces, but it provides a great starting point. Once you’ve created schemas, you can run all of the documents you produce through them and make sure they’re free of defects. I found a bug in my code the first time I added schema validation to my unit test.
Anyway, I’ve been very much in the minimalist camp when it comes to dealing with XML. DTDs, schemas, namespaces and so forth have never been something that I bother with. I just grab the easiest library to use that I can find and covert the XML into data structures (or vice versa) in my application. Now I’m thinking that’s the wrong approach, especially when you’re producing XML rather than consuming it.