Monday, December 21, 2009

Gettin' Groovy with xml validation

So, I wanted to be able to tell learn some things about the validity of a particular xml document I was working with a few days ago. If you use something like XMLSpy or the xml plugin for Notepad++, they will display only the first validation error. So, I wrote a Groovy script to let me control the amount of errors reported, and collect some statistics about the document. I call it ValidateMe. And now, I'm sharing it with you. You can get the script off its Google Code page. As usual, it's MIT licensed, so you can do pretty much whatever you want with it. It's usage is described by running 'groovy validateMe.groovy help'. It's pretty straightforward, about 130 lines or so, but I think it's pretty slick.

As a result of doing this, I also learned that you can have multiple classes in the same .groovy script file, as long as the class with the main method is first.