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();
factory.setNamespaceAware(true);
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.
2 comments:
mai kay siao leh
Yes, I agree 100%
Post a Comment