07 June 2006

Parsing XSDs

When things are little quiet on the blog front usually means its hot on the work front. I don't want to say the inverse is true since that could say something about my daily acitivities.

So this is just a short and sweet post today.

I've been tackling a task this week which required me to provide some details about the OC4J configuration parameters. To make it easy, I thought I'd derive the data I wanted directly from the OC4J schema files -- after all they pretty much define what our config files can contain.

Besides the drudgery of writing the parsing routines by hand, the biggest thing I discovered was that in order to parse an XSD file you have to set the namespaceAware property to true.

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder parser = factory.newDocumentBuilder();
Document document = parser.parse(fis);

Until I did that, the document returned was basically null.

As I was working on this short term task -- my mind kept thinking back to what would the good practices for working with XSD files themselves? Could/should I have spent a little more time checking into using Castor/JAXB/commons-digester/etc. instead of crufting something manually? Would that have been worth the effort?

I ended up doing what I knew would work to get the job done, but it's code I'll never let off my laptop, I promise.


Anonymous said...

mai kay siao leh

Anonymous said...

Yes, I agree 100%