1000 Java Tips ebook
Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java
programming articles and tips. Please take your copy here.
Take your copy of free "Java Technology Screensaver"!.
RELAX NG with Custom Datatype Libraries
JavaFAQ Home » Java Tools
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:
DatatypeFactory. This article
demonstrates these interfaces by verifying that a number is prime.
The RELAX NG XML schema language has achieved huge success over the past
three years; this is due in large part to its incredibly clean and
straightforward syntax, especially compared to the W3C XML Schema language.
Numerous groups, including OpenOffice, DocBook, and the Text Encoding
Initiative, have adopted the RELAX NG schema language. RELAX NG has even begun
to replace W3C schemas within the W3C, where both the SVG and XHTML working
groups are writing their schemas in RELAX NG, then translating them to DTDs and
W3C XML Schemas. While RELAX NG doesn't mandate support for XML schema
datatypes, in practice, major implementations such as Jing and Sun's Multischema
Validator do support them.
However, in all the excitement over how much better RELAX NG does the same
things as the W3C XML Schema language, the fact that it can actually do quite a
bit more has been overlooked. In particular, unlike the W3C XML Schema language,
RELAX NG is not limited to one preordained collection of primitive data types
with a limited set of facets for extension. RELAX NG enables developers to
define custom type libraries that can assert any constraints a program can
verify. For example, W3C schemas cannot validate these constraints:
- A number is prime.
- Every left parenthesis in a string is matched by a right parenthesis.
- The value of the
SKU attribute matches a record in the
- The content of an element is correctly spelled, as determined by
consulting a dictionary file.
Printer Friendly Page
Send to a Friend
Search here again if you need more info!