views:

325

answers:

1

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.

+1  A: 

org.apache.axis.types.NMToken from Apachie Axis (the webservice framework) has a static isValid(String) method and may be what you need (or may be more than you need).

NMToken in the Axis API

18Rabbit
As much as I don't like having to package a whole framework for one class (especially a library as ghastly as Axis), I think this is the best I'm going to get :)
skaffman