OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

relax-ng message

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [Elist Home]


Subject: Re: RELAX NG FAQ



Answers from David and Murata-san were checked in to the repository.


Also, the attached faq.html is the latest snapshot transformed into HTML.
(We definitely need more fancy stylesheet.)


regards,
--
Kohsuke KAWAGUCHI                          +1 650 786 0721
Sun Microsystems                   kohsuke.kawaguchi@sun.com
Title: Frequently Asked Questions about RELAX NG

Frequently Asked Questions about RELAX NG

$Revision: 1.6 $


1 How is "RELAX NG" pronounced?
2 Why does RELAX NG use an XML syntax?
3 Why is RELAX NG so verbose?
4 What about entity declarations? Why doesn't RELAX NG allow me to declare entities? What do I do if I need to declare an entity?
5 What about notation declarations? Why doesn't RELAX NG allow me to declare notations? What do I do if I need to declare a notation?
6 Why doesn't RELAX NG do type assignment? How can I use RELAX NG if I want to do schema-based type assignment?
7 How can I do data-binding with RELAX NG?
8 Why should I care about RELAX NG when I have DTDs?
9 What about ID/IDREF? Why doesn't RELAX NG do ID/IDREF? What do I do if I need ID/IDREF?
10 Why doesn't RELAX NG provide a feature like key, keyRef in XML Schema? What do I do if I need this functionality?
11 Why doesn't RELAX NG provide a documentation element?
12 I read that RELAX NG is based on "regular tree languages"? What's that all about? Does it have any practical benefits?
13 Why does RELAX NG base itself on grammars? Isn't a constraint-based approach like Schematron more powerful?
14 What about the XML Schema processContents="strict|lax|skip" feature? How can I do this in RELAX NG?
15 What about exclusions (as in SGML)? Why doesn't RELAX NG support exclusions? What do I do if I need this functionality?
16 Why doesn't RELAX NG support minOccurs/maxOccurs as XML Schema?
17 (Something about namespaces. Why does RELAX NG take the approach that it does? How does RELAX Namespace fit in? Compare with W3C Schema approach.)
18 (Something about attribute/element content models.)
19 I read that, unlike DTDs and XML Schema, RELAX NG does not prohibit ambiguous content models? Does this have any practical benefit?
20 What's the use of the interleave element in RELAX NG?
21 What's the use of the parentRef element in RELAX NG? What's the use of nested grammars?
22 What's the use of the combine attribute in RELAX NG?
23 What's the difference between the empty pattern and the notAllowed pattern?
24 Why do I need RELAX NG, when W3C XML Schema is there?
25 Why doesn't RELAX NG modify the infoset?
26 I want to specify the default attribute value. How can I do that?
27 How can I express the concept of the inheritance?
28 How/where can I learn more about RELAX NG?
29 What kind of tools are available now?
30 What is the relationship between RELAX/TREX and RELAX NG

1 How is "RELAX NG" pronounced?

It's pronounced "relaxing".

2 Why does RELAX NG use an XML syntax?

Seriously, is there any other choice?

If you don't want to write RELAX NG in XML syntax, there is a tool by James Clark that allows you to write RELAX NG schema in non-XML syntax and that tool will convert it to XML syntax for you.

3 Why is RELAX NG so verbose?

If you find it too verbose for hand writing, there are tools that let you write one in more concise syntax. Check out the tools section.

Compared to DTD syntax all XML based schema is more verbose.

Comparing

<!ELEMENT foobar ( A, ( B | C )+, D) >

to its equivalent is always going to be more verbose. As with everything the trade-offs bring advantages. RELAX is much more expressive than DTD, and also fixes the omissions and limitations in DTD. The price is that you have to accept more syntax.

However, notice that well written and indented RELAX is vastly more readable and significantly less verbose than the equivalent W3C Schema offering.

Verbose tends to one of those subjective issues, but on the whole we feel that RELAX offers a good balance and is not excessive.

RELAX NG heavily uses elements for representing patterns. This approach makes RELAX NG simple but verbose. Feedback from schema authors is very welcome. In addition to the standard syntax, there are some proposals and implementations for more concise syntax (see the tools section).

4 What about entity declarations? Why doesn't RELAX NG allow me to declare entities? What do I do if I need to declare an entity?

5 What about notation declarations? Why doesn't RELAX NG allow me to declare notations? What do I do if I need to declare a notation?

6 Why doesn't RELAX NG do type assignment? How can I use RELAX NG if I want to do schema-based type assignment?

Actually you can do the type assignment if you use a tool that supports it. For example, Sun Multi-Schema XML Validator supports the type assignment.

Since RELAX NG allows ambiguous grammars, type-assignment is not always possible. And in some other cases, type-assignment is possible but needs multiple passes. That's one of the reasons why we don't have type-assignment in our core spec.

7 How can I do data-binding with RELAX NG?

There are not many, but there certainly exists tools for data-binding. For one, you can use Relaxer. Check out the tools section for more.

8 Why should I care about RELAX NG when I have DTDs?

9 What about ID/IDREF? Why doesn't RELAX NG do ID/IDREF? What do I do if I need ID/IDREF?

10 Why doesn't RELAX NG provide a feature like key, keyRef in XML Schema? What do I do if I need this functionality?

11 Why doesn't RELAX NG provide a documentation element?

If you want to write documentation in RELAX NG schema, you can do it by simply using a namespace of your choice, like this:

<element xmlns:doc="my:own:choice:of:namespace:URI">
  <anyName/>
  <doc:document>
    Here is my documentation
  </doc:document>
  ...
</element>
	

RELAX NG allows you to write any elements and attributes to anywhere as long as it belongs to the namespace other than the RELAX NG namespace. So the above is completely legal.

Or another way to do this is to use elements of XHTML, DocBook, TEI or whatsoever. In this way, you can format your documents quite nicely.

<element xmlns:xhtml="http://www.w3.org/1999/xhtml">
  <anyName/>
  <xhtml:div>
    <xhtml:h1>Overview of this element</xhtml:h1>
    <xhtml:p>This element is used to do some craptacular thing</xhtml:p>
  </xhtml:div>
  ...
</element>
	

If you are looking for a plain simple text-only documentation, then you may want to use the documentation tag specified in the "RELAX NG DTD compatibility specification". No, you don't need to read the spec. Just use the documentation element in the http://relaxng.org/ns/annotation/0.9 namespace. For example,

<element xmlns:a="http://relaxng.org/ns/annotation/0.9">
  <anyName/>
  <a:documentation>
    This element is used to save the world from starvation.
  </a:documentation>
  ...
</element>
	

As I wrote earlier, you can write this element anywhere in the schema.

12 I read that RELAX NG is based on "regular tree languages"? What's that all about? Does it have any practical benefits?

As long as you are using RELAX NG, you don't need to know anything about those geeky stuff. But yes, it does have several practical benefits.

  1. The validation algorithm becomes simple because this theory is well-studied. This contributes to make validators smaller and faster.

  2. It enables static analysis of schemas: is anything allowed by one schema also allowed by another schema?

13 Why does RELAX NG base itself on grammars? Isn't a constraint-based approach like Schematron more powerful?

One answer to this question is, the grammar-based approach is well-studied by scientists and (therefore) the validation is relatively fast.

Also, there will be tools available which let you combine RELAX NG and Schematron. Check out the tools section.

14 What about the XML Schema processContents="strict|lax|skip" feature? How can I do this in RELAX NG?

There is no special primitive for the wild card in RELAX NG, but you can use the "name class" to achieve the same effect.

Generally, "skip" is easy to mimic, but "strict" and "lax" are hard. For example, the following pattern corresponds with:

<any processContents="skip" namespace="##other"/>
<define name="wildcard.skipOther">
  <element>
    <anyName>
      <except><nsName/></except>
    </anyName>
    
    <zeroOrMore>
      <choice>
        <text/>
        <attribute><anyName/></attribute>
        <ref name="wildcard.skipOther"/>
      </choice>
    </zeroOrMore>
  </element>
</define>

15 What about exclusions (as in SGML)? Why doesn't RELAX NG support exclusions? What do I do if I need this functionality?

16 Why doesn't RELAX NG support minOccurs/maxOccurs as XML Schema?

If you really want to use minOccurs/maxOccurs, you can use a tool like this, which recognizes minOccurs/maxOccurs and expand it to the normal RELAX NG syntax.

17 (Something about namespaces. Why does RELAX NG take the approach that it does? How does RELAX Namespace fit in? Compare with W3C Schema approach.)

18 (Something about attribute/element content models.)

19 I read that, unlike DTDs and XML Schema, RELAX NG does not prohibit ambiguous content models? Does this have any practical benefit?

20 What's the use of the interleave element in RELAX NG?

One of the frequent use would be to implement an unordered content model ( XML Schema's <all> particle.)

Another nice technique is to implement a "set" of tokens.

<list>
  <interleave>
    <optional>
      <value>abc</value>
    </optional><optional>
      <value>def</value>
    </optional><optional>
      <value>ghi</value>
    </optional>
  </interleave>
</list>

21 What's the use of the parentRef element in RELAX NG? What's the use of nested grammars?

22 What's the use of the combine attribute in RELAX NG?

Practically, combine="choice" and combine="interleave" serve two completely different purposes.

  • One of the use case of combine="choice" is to create an implicit "class" of elements.

    <define name="inline.class" combine="choice">
      <element name="b"> ... </element>
    </define>
    
    <define name="inline.class" combine="choice">
      <element name="i"> ... </element>
    </define>
    

    In this way, each element can collaboratively form a class of elements, without any central control. This is useful when writing a modularized schema.

  • Another common use of combine="choice" is to extend an already defined "class" of elements.

    <define name="list.class">
      <choice>
        <ref name="dl"/>
        <ref name="ul"/>
        <ref name="ol"/>
      </choice>
    </define>
    
    <define name="list.class" combine="choice">
      <ref name="xl"/>
    </define>		
    			

23 What's the difference between the empty pattern and the notAllowed pattern?

24 Why do I need RELAX NG, when W3C XML Schema is there?

Consider why most people prefer to drive cars, even though they could all be buying Hummers instead, after all Hummers are now available.

A cursory inspection of the requirements specification for W3C Schema gives a good sense of how RELAX is designed to fulfil a clear mission that is concise and descrete.

By limiting the scope to structure definitions, RELAX avoids the drawbacks of W3C Schema, giving a much more elegant and predictable toolset.

A further issue with W3C Schema is implementation consistency. With a large and complex specification behaviour of the software implementations is an impediment to consistent deployment. Something you program into your schema may not behave as you intended on certain of your customer environments and vice versa.

A simpler specification reduces the risks and gives a more reliable business deployment.

25 Why doesn't RELAX NG modify the infoset?

26 I want to specify the default attribute value. How can I do that?

27 How can I express the concept of the inheritance?

Here is a proposal by MURATA Makoto for capturing inheritance in RELAX NG.

One way to do this is to invent a new syntax of RELAX NG that has OO-fravor, and make it convertible to normal RELAX NG. In fact, there are tools that do this.

28 How/where can I learn more about RELAX NG?

29 What kind of tools are available now?

30 What is the relationship between RELAX/TREX and RELAX NG

In short, RELAX (to be precise, RELAX Core) and TREX are parents of RELAX NG.



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [Elist Home]


Powered by eList eXpress LLC