I maintain a DTD which is used to specify XML documents which are mostly marked up in the dialect specified by the DTD ('ADL'), but in which there are three elements whose contents are intended to be arbitrary XHTML 1.1.
Peter Flynn helpfully pointed me to RelaxNG, which does indeed prove a very nice syntax for specifying a grammar (I'm using the XML syntax which I find easier than the 'compact' syntax, but as they're interchangeable that's preference. I see that RelaxNG has a mechanism for referencing external documents:
http://www.relaxng.org/tutorial-20011203.html#IDA04YR
I also found on W3C's website a specification - possibly out of date - of XHTML 2.0 as a series of RelaxNG modules:
http://www.w3.org/TR/2003/WD-xhtml2-20030506/relax_module_defs.html
(I couldn't find anywhere these were downloadable as a zip or similar, but I have copied and pasted into a set of working files to experiment with).
However, I haven't worked out how these are supposed to work together since they clearly depend on one another but make no use either of the 'externalRef' mechanism or of the 'include' mechanism. I do note that they make heavy use of the 'combine' mechanism.
The RelaxNG tool I'm currently using, trang, allows one input grammar file only - it doesn't permit several input grammar files to be specified. So I haven't yet worked out how to use multiple XHTML2 modules together. Also, when I try trang on .rng files which contain externalRefs, I get:
simon@gododdin:~/workspace/adl/schemas$ java -jar /home/simon/Downloads/ useful/trang-20091111/trang.jar adl-1.4.rng test.xsd /home/simon/workspace/adl/schemas/adl-1.4.rng:1011:52: error: sorry, externalRef is not yet supported
so I don't know whether I'm doing what I'm doing right. But what I'm trying to do is specify that (for example) an ADL headmatter element may contain xhtml script, link, meta and style elements, so I in the adl.rng
I have:
<grammar xmlns="
http://relaxng.org/ns/structure/1.0" datatypeLibrary="
http://www.w3.org/2001/XMLSchema-datatypes" ns="
http://bowyer.journeyman.cc/adl/unstable/adl/"> .... <define name="headmatter"> <element name="headmatter"> <ref name="attlist.headmatter"/> <externalRef href="permitted-html-head.rng"/> </element> </define> <define name="attlist.headmatter" combine="interleave"> <empty/> </define>
and in a separate file 'permitted-html-head.rng' I have
<?xml version="1.0" encoding="UTF-8"?>
<grammar xmlns="
http://relaxng.org/ns/structure/1.0" datatypeLibrary="
http://www.w3.org/2001/XMLSchema-datatypes" ns="
http://www.w3.org/2002/06/xhtml2/">
<start>
<ref name="permitted-xhtml-head" />
</start>
<define name="permitted-xhtml-head">
<zeroOrMore>
<choice>
<element name="content">
<externalRef href="xhtml-2/xhtml-scripting.rng" /> <externalRef href="xhtml-2/xhtml-link.rng" /> <externalRef href="xhtml-2/xhtml-meta.rng" /> <externalRef href="xhtml-2/xhtml-style.rng" /> </element> </choice> </zeroOrMore> </define> </grammar>
What I hope this is specifying is, e.g.:
<adl:headmatter>
<adl:content>
<xhtml:link rel="stylesheet" type="text/css" href="styles.css" /> <xhtml:meta name="generator" content="Application description language framework" /> </adl:content> </adl:headmatter>
I'd much rather not have the <adl:content> tag in there but I haven't yet worked out a way of getting rid of it. I do specifically want to keep the namespaces 'adl:' and 'xhtml:' distinct.
So, the questions:
Given that trang does not (yet) handle externalRefs, is there a tool I can use which will translate a RelaxNG grammar using externalRefs into an XSD schema?
And, generally, am I on the right lines?