RELAX NG with custom datatype libraries:
RELAX NG can do almost everything the W3C XML Schema language can do, including verifying constraints on text content and attribute values specified with the W3C XML Schema simple types. However, some constraints still can't be stated in anything less than a Turing-complete language, and RELAX NG is not such a language. Fortunately, you can extend RELAX NG dynamically with custom validation code — written in the Java™ programming language — that checks constraints that RELAX NG itself can't specify. This requires implementing three interfaces: Datatype, DatatypeLibrary, and DatatypeFactory. This article demonstrates these interfaces by verifying that a number is prime.