[relaxng-user] Converting Relax-NG to Schema and DTD

Daniel Vogelheim Daniel.Vogelheim at sun.com
Tue Jan 13 16:20:43 ICT 2004


Hi David and others,

you wrote:

>>I wish someone would write me
>>a RelaxNG equivalent of "soelim", ie something which expanded all includes
>>and activated the overrides.
>>    
>>
>
>this is called rng2srng, by Kohsuke KAWAGUCHI. It is a program in Java, which uses
>Jing to simpligy RELAX NG and then dumps it as a single grammar.
>
>If it is an option, then it is the way to go. However, it makes a grammar not human-readable.
>  
>

That was a good suggestion. I ran my grammer through rng2srng, and it 
reduced the problems in the subsequent DTD conversion from 160 to 40. 
Furthermore, ca. half of those are due to one particular construct, 
which can be easily resolved manually... :-)

Using the same on XSD doesn't really make sense, since the resulting XSD 
becomes rather unreadable...

I am a bit surprised at some of the problems. In the original grammer, I 
liberally used defines with combine, i.e. something like:
[...] <zeroOrMore> <ref name="bla"/> </zeroOrMore>
[...] <define name="bla" combine="choice"> <element 
name="...">...</element></define>
[...] <define name="blerk" combine="choice"> <element 
name="...">...</element></define>
This caused an error when generating DTDs, even a straight-forward 
mapping to a content model (bla|blerk|...)* is available. This kind of 
error disappeared after using rng2srng.

Another problem, which persists after rng2srng, stems from 
inter-dependent attribute values. In a few cases, attributes depend on 
each other. E.g. to encode values of different types, we use a 
value-type="...". For different value types, there are different 
attributes. E.g. value-type="string" and string-value="...", or 
value-type="data" and date-value="...". This can be encoded in Relax-NG as:
<choice>
  <group>
    <attribute name="value-type"><value>string</value></attribute>
    <attribute name="string-value"><data type="string"/></attribute>
  </group>
  <group>
    <attribute name="value-type"><value>date</value></attribute>
    <attribute name="date-value"><data type="date"/></attribute>
  </group>
</choice>
Trang can't handle this when translating to DTD ("sorry, ambigous 
attribute choice not handled").
A good approximating representation (that the used previously in the 
manually created DTD) would be:
<!ATTLIST ... value-type (string|date) #REQUIRED>
<!ATTLIST ... date-value (#PCDATA) #IMPLIED>
<!ATTLIST ... string-value (#PCDATA) #IMPLIED>


I suspect part of the problem (for at least the first issue) is that 
Trang tries to make a good translation, preserving the author's 
intentions, as opposed to a merely correct one. The first issue can be 
solved with rng2srng, but that pretty much destroys the original 
structure. Hence I'm not surprised Trang doesn't do that. OTOH, for DTD 
output specifically, transformations such as combining <define 
combine="..."> definitions would be a good idea, since that particular 
aspect of the original schema cannot be preserved through the 
translation to DTDs anyway.


I'll see if James Clark has an opinion on this, and would want to 
include this into Trang.

Sincerely,
Daniel





More information about the relaxng-user mailing list