rc3.org

Strong opinions, weakly held

XML schemas are fun

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.

2 Comments

  1. My favorite tool was XML Spy by Altova. I would use it to do the XML to HTML conversions as it also had a nice XSLT editor. That was in the days when you couldn’t count on the browsers (well at least one very popular browser anyway) to render the HTML. I would render it with XML Spy and then post the HTML. I was just fooling around, but I really did enjoy working with that software.

    When I made the switch to the Mac I left all that behind as Altova’s programs didn’t run on OS X. Now I see that they have ported them to the Mac. I may have to make a purchase. As you know, I enjoy playing just enough to be dangerous.

  2. We started using DTDs about 5 years ago when we adopted a standard for receiving XML from other groups/vendors/companies. DTDs are handy for a couple of reasons. Firstly, you can give anyone the appropriate DTD and they will know how to construct a valid XML document. Secondly, if you use the right parsing/validating tools, you can quickly validate the XML document against the DTD to know if you should accept/reject the document.

    We’re a Perl/Solaris shop and we use XML::LibXML (the Perl bindings for the gnome libxml2 library) which provides lightning fast parsing and accurate DTD validation.

Leave a Reply

Your email address will not be published.

*

© 2016 rc3.org

Theme by Anders NorenUp ↑