Easy to Learn Java: Programming Articles, Examples and Tips

Start with Java in a few days with Java Lessons or Lectures


Code Examples

Java Tools

More Java Tools!

Java Forum

All Java Tips


Submit News
Search the site here...
Search the JavaFAQ.nu
1000 Java Tips ebook

1000 Java Tips - Click here for the high resolution copy!1000 Java Tips - Click here for the high resolution copy!

Java Screensaver, take it here

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 Go to all tips in Java Tools

Bookmark and Share
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.

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 products database.
  • The content of an element is correctly spelled, as determined by consulting a dictionary file.

Read more here

 Printer Friendly Page  Printer Friendly Page
 Send to a Friend  Send to a Friend

.. Bookmark and Share

Search here again if you need more info!
Custom Search

Home Code Examples Java Forum All Java Tips Books Submit News, Code... Search... Offshore Software Tech Doodling

RSS feed Java FAQ RSS feed Java FAQ News     

    RSS feed Java Forums RSS feed Java Forums

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest 1999-2006 by Java FAQs Daily Tips.

Interactive software released under GNU GPL, Code Credits, Privacy Policy