Sophie

Sophie

distrib > Fedora > 14 > i386 > by-pkgid > 7f7c01e85ae5bab3fb1deda72d3a9c7a > files > 10

msv-manual-2009.1-3.fc14.noarch.rpm

<html>
<head>
	<meta http-equiv="CONTENT-TYPE" content="text/html; charset=iso-8859-1">
	<title>MSV: RELAX NG User-Defined Datatype Libraries</title>
	<!-- $Id: RNGDatatypeLibrary.html 1220 2001-10-12 01:10:50Z Bear $ -->
	<style>
		pre {
			background-color: rgb(240,240,240);
		}
	</style>
</head>
<body>
<h1>
	RELAX NG User-Defined Datatype Libraries
</h1>
<div align="right" style="font-size:smaller">
Written by <a href="mailto:kohsuke.kawaguchi@sun.com">Kohsuke KAWAGUCHI</a>
</div>


<h2>Introduction</h2>
<p>
	The specification of RELAX NG proclaims that it can work with external datatype libraries. The implication is that you can implement your own datatype library and it should work with existing tools like MSV.
</p><p>
	To serve this objective, James Clark and Kohsuke KAWAGUCHI developed a datatype interface for Java, which is hosted at <a href="http://relaxng.sourceforge.net">SourceForge</a>.
</p><p>
	MSV supports this interface, so you can write your own datatype library on top of this interface and it will work with MSV.
	
	One can also expect that a datatype library developed by using this interface will work with many other RELAX NG tools as well.
</p><p>
	Custom datatype libraries are very flexible solutions. For example, you can write a datatype that checks the product code by querying a database.
</p>


<h2>Sample</h2>
<p>
	For more information about how to develop a datatype library for RELAX NG, please download <a href="http://www.thaiopensource.com/relaxng/datatype-sample.zip">this</a> (which is developed and maintained by Thai Open Source Software Center.)
</p>


<h2>Writing Portable Schema</h2>
<p>
	One problem of using a custom datatype library is the portability; once you use it, your schema will not work with other non-Java RELAX NG tools.
</p><p>
	This section explains a technique to avoid this problem. Consider the following schema:
</p>
<pre><xmp>
<grammar datatypeLibrary="urn:custom:datatype:library">
  <start>
    <element name="root">
      <data type="myType"/>
    </element>
  </start>
</grammar>
</xmp></pre>
<p>
	As you see, this schema is not portable since some other tools may not recognize "myType" datatype.
</p><p>
	You can avoid this problem by writing two schemas. The first schema would be:
</p>
<pre><xmp>
<grammar>
  <start>
    <element name="root">
      <ref name="myType" />
    </element>
  </start>
  
  <define name="myType">
    <data type="string" />
  </define>
</grammar>
</xmp></pre>
<p>
	The point is, to provide a &lt;define> for a datatype. This is much like writing a parameter entity for a datatype in DTD.
</p><p>
	Then write a second schema as follows:
</p>
<pre><xmp>
<grammar datatypeLibrary="urn:custom:datatype:library">
  <include name="original.rng">
    <define name="myType">
      <data type="myType" />
    </define>
  </include>
</grammar>
</xmp></pre>
<p>
	The first schema is portable since it doesn't use any of the custom datatype libraries. Instead it falls back to the built-in "string" type.
</p><p>
	The second schema is relatively short. It just overrides the definition of "myType" by using the custom datatype library. So in environments where the custom datatype library is available, you can use this schema to get a better validation.
</p>
</body>
</html>