I have some application code which generates XML documents, which are then validated against an XML Schema. The schema makes use of NMTOKEN types, and occasionally, the generated XML contains string values which are illegal NMTOKENs (e.g. they contain spaces or weird punctuation). The Xerces schema validation catches it OK, of course, but I'd like to catch it earlier, in my own code, and handle it more gracefully.

I was going to write my own isValidNMTOKEN method, and check that each charcter is valid according to the schema spec, but I was hoping there was an existing utility out there that would do this for me.

Sort of like a commons-lang for XML. Nothing useful in xml.apache.org/commons, sadly.