The XML importer reads sample XML documents and guesses at implicit schema definitions, based on those documents. When the suffix xml is used, Relaxer uses the XML importer.
List 4.3.1.1[hello.xml] is a sample XML document.
<greeting to="everybody" from="relaxer.org" date="2001-02-10"> <title>Hello World</title> <message>Welcome to Relaxer World!</message> </greeting>
To import an XML document, simply specifies an XML document file as follows:
$ relaxer -rng hello.xml
As a result, Relaxer generates one file, as follows:
List 4.3.1.2[hello.rng] is the generated RELAX NG schema, which is avilable for an XML document 'hello.xml'.
<?xml version="1.0" encoding="UTF-8" ?> <grammar datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes" \ xmlns="http://relaxng.org/ns/structure/1.0" \ xmlns:java="http://www.relaxer.org/xmlns/relaxer/java" \ xmlns:jdbc="http://www.relaxer.org/xmlns/relaxer/jdbc" \ xmlns:relaxer="http://www.relaxer.org/xmlns/relaxer"> <start> <ref name="greeting"/> </start> <define name="greeting"> <element name="greeting"> <attribute name="date"> <data type="date"/> </attribute> <attribute name="from"> <data type="token"/> </attribute> <attribute name="to"> <data type="token"/> </attribute> <element name="title"> <data type="token"/> </element> <element name="message"> <data type="token"/> </element> </element> </define> </grammar>
List 4.3.2.1[hello.xml] is the sample XML document using previous example.
<greeting to="everybody" from="relaxer.org" date="2001-02-10"> <title>Hello World</title> <message>Welcome to Relaxer World!</message> </greeting>
List 4.3.2.2[hello2.xml] is an another sample XML document.
<greeting to="everybody" from="relaxer.org"> <title>Hello World</title> <subtitle>Initial application</subtitle> <message>Welcome to Relaxer World!</message> </greeting>
Relaxer can generate a RELAX schema from multiple XML documents. To import multiple XML documents, simply specifies schema files as follows:
$ relaxer -rng hello.xml hello2.xml
As a result, Relaxer generates one file, as follows:
List 4.3.2.3[hello.rng] is the generated RELAX NG schema, which is avilable for XML documents 'hello.xml' and 'hello2.xml'.
<?xml version="1.0" encoding="UTF-8" ?> <grammar datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes" \ xmlns="http://relaxng.org/ns/structure/1.0" \ xmlns:java="http://www.relaxer.org/xmlns/relaxer/java" \ xmlns:jdbc="http://www.relaxer.org/xmlns/relaxer/jdbc" \ xmlns:relaxer="http://www.relaxer.org/xmlns/relaxer"> <start> <ref name="greeting"/> </start> <define name="greeting"> <element name="greeting"> <optional> <attribute name="date"> <data type="date"/> </attribute> </optional> <attribute name="from"> <data type="token"/> </attribute> <attribute name="to"> <data type="token"/> </attribute> <element name="title"> <data type="token"/> </element> <optional> <element name="subtitle"> <data type="token"/> </element> </optional> <element name="message"> <data type="token"/> </element> </element> </define> </grammar>