The conversion from XSD to RelaxNG is performed by one XSLT, XSDtoRNG.xsl which is published in the xsdtorngconverter google code project.

You can trigger the conversion from that web page using the demonstration block below. However if your schema is big, I recommend you to download XSDtoRNG.xsl and make the conversion locally with any standard XSLT API.

Schema conversion

Follow the steps :

  1. Write a XSD schema in the textarea.
  2. Click on "Convert ->". The result of the conversion is dumped in the second textarea.

Benefits

XSD is a complex language of XML specification and lots of its markups are, in my opinion, useless. RelaxNG has been created by specialists of XML technologies, at a moment when XML has became a lot more mature and a lot more used.

I think RelaxNG reduces the problem of complexity of XML specifications. And it also gives good habits which helps making better XML, like creating attributes nodes instead of surrounding any value by opening/closing markup.

That XSLT conversion may be less "exact" than a conversion performed by a Java API like Sun Multi-Schema Validator. But it will keep the original structure of your schema, which makes it simpler to correct visually, as it is often necessary. As a single XSLT file, it is also simple to use from any programming language.

Explanation

Correspondances table between XSD and RelaxNG

XSD RelaxNG
<schema> <grammar>
<element> <element> (may be declared as a possible start, see below)
<attribute> <attribute>
<import>, <include>, <redefine><include>
<choice> <choice>
<annotation> <documentation>
<documentation> redundant with <annotation>
<appinfo> children copied
<union> <choice>
<union memberTypes=""> <choice> then call the "type" template on each memberType
<list> <list>
<list itemType=""> <list> then call the "type" template on itemType
<complexType name="">, <simpleType name="">, <group name="">, <attributeGroup name=""><define>
<*(default behaviour) ref="">call the "type" template
<sequence>, <complexContent>, <simpleType>, <complexType>useless
<extension base=""> call the "type" template on base
<any> <element> <anyName> <text>
<anyAttribute> <attribute> <anyName> <text>
<restriction> followed by <enumeration><choice>
<restriction base="">call the "type" template on base
<enumeration value=""><choice> <value>
<minInclusive>, <minExclusive>, <pattern>, ...<param name="minInclusive, ...">
<all> <interleave> <optional>
@default on attribute <a:defaultValue>
@default on element not supported in RelaxNG
@use="optional" <optional>
@maxOccurs="unbounded" @minOccurs="0"<zeroOrMore>
@maxOccurs="unbounded" <oneOrMore>
@minOccurs="0" <optional>
@minOccurs="n" copies n times the template

The "type" template

@type="anyType" <data type="string">
@type="xs:..." or @type="xsd:..."<data type="">
@type="...:type_name" <ref name="type_name">
@type="" <ref name="">

Possible start

If the <xs:element> is directly under <xs:schema> then is is declared as a possible start of the XML so the following RelaxNG is dumped :

	<rng:start combine="choice">
		<rng:ref name="elementName"/>
	</rng:start>
	<rng:define name="elementName">
		...
	</rng:define>

Participation

All those developments are released under Cecill licence.

The project Forms Generator is available on a svn, contact me for more information. In the future, a project might be created on sourceforge.

Projects svg 3d, XSD to RelaxNG converter, javascript SAX parser, javascript RelaxNG validator, javascript datatype library are published on Google code. Project javascript SAX parser is also published on Github.

Requirements

In order to have javascript working as expected, please use last version of firefox.

For the applets, you will need to have java installed on your computer.