[1067908 views]

[]

[toggle ads]

Odi's astoundingly incomplete notes

New entries | Code

Fixing a JDOM design flaw

The problem was simple: Create an XML document and validate it against a given schema before sending it to the customer.

The solution seemed simple:
  1. Use JDOM to create a document model in memory.
  2. Use DOMOutputter to convert it to a W3C DOM
  3. Validate the DOM against an XML schema using Xerces through JAXP
That's when I encountered a strange bug. Somehow the validator did not like my input. The problem turned out to be missing namespace support in the DOM. Well, my DOM nodes really were in no namespace, so it didn't surprise me that the DOM did not support namespaces. But the schema validation needs it unconditionally. Whether the nodes are in a namespace or not.
It boiled down to the problem that JDOM's DOMOutputter tried to be clever and created nodes without namespace support if the node was in no namespace. I addressed this by patching this class a little, so it gives you more control over this behaviour. Now it works. I hope that the JDOM people will include the patch in their next release.

Update: the patch has been included into the jdom-1.1 release

posted on 2006-05-23 11:46 CEST in Code | 0 comments | permalink