Well, I have a working example. Notes below.

TOPIC: Datatype libraries in Relax NG
DATE:2005-09-14T10:45:38
KEYWORDS:datatypes

* Using Relax NG with extension data types.

Jing 20030619 used.

Attempting to add a new data type to Jing, I tried out James example
(sample/datatype/src/com/thaiopensource/datatype/sample/BalancedString.java).

1. in the datatype directory the datatype-sample.rng has the namespace
incorrectly defined, presumably not updated.

Should be

 <element name="balancedString"
   xmlns="http://relaxng.org/ns/structure/1.0";
   datatypeLibrary="http://www.thaiopensource.com/relaxng/datatypes/sample";>
  <data type="balancedString"/>
 </element>


That aside it ran and the valid.xml example parsed to the schema, using

java -cp jing.jar;data-sample.jar \
 com.thaiopensource.relaxng.util.Driver \
  datatype-sample.rng valid.xml


Trying to emulate this example I built a tiny Java file supposedly
replicating BalancedString.java, using my own namespace etc.

The points of note: 

1. In the java file

Declare the namespace to be used for the library

  private static final String DATATYPE_LIBRARY
    = "http://www.rnib.org/relaxng/datatype/units";;
  private static final String TYPE = "px";

This declares both the namespace and the actual datatype
which will be declared in the schema file

2. In the Schema file

 <element name="unit"
   xmlns="http://relaxng.org/ns/structure/1.0";
   datatypeLibrary="http://www.rnib.org/relaxng/datatype/units";>
  <data type="px"/>
 </element>

Note the matching namespace and datatype.

3. Building the jar file.

This is where I had fun.

In sample/datatype/index.html James mentions
com.thaiopensource.datatype.sample.SimpleDatatypeLibrary which is
provided. What I found no mention of, was the Factory idea (of which I
know little), yet which seems to provide the basic link between jing
and the new datatype. In James file datatype-sample.jar, there exists
a line

   -rw-rw-rw-        50  22-Sep-2001  11:10:46  \
   META-INF/services/org.relaxng.datatype.DatatypeLibraryFactory

which I found odd.

Seemingly (and I'm guessing here, please tell me if I'm wrong), this
file is generated and added to the jar to provide Jing with the list
of classes which provide datatypes. So James example contains the line

  com.thaiopensource.datatype.sample.BalancedString

which is the package name containing a class which implements the
balancedString type. As often with James, nice and simple once
understood. Bloody impossible until then!

So I created a file 

  META-INF\services\org.relaxng.datatype.DatatypeLibraryFactory

with the single line 

 org.rnib.datatype.units.Px

after which the test I had generated ran perfectly.

 <doc>
  <unit>45px</unit>
  <unit>45 px</unit>
  <unit>.12 px</unit>
 </doc>

The third example of unit fails with the error

  units.xml:6:20: error: bad character content for element

  
Hope this helps others.


regards DaveP


------------------------ Yahoo! Groups Sponsor --------------------~--> 
Most low income households are not online. Help bridge the digital divide today!
http://us.click.yahoo.com/cd_AJB/QnQLAA/TtwFAA/2U_rlB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/rng-users/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to