[relaxng-user] Trang handling of (text|element) content
J. David Eisenberg
catcode at catcode.com
Fri Oct 24 19:36:29 ICT 2003
By "popular demand" my XML class wants to know about XML Schema.
One example is a document that consists of one or more lists.
A list consists of one or more items. Each item consists of text
or a list. (Yes, I'm teaching about recursive definitions.)
Sample document follows:
<document>
<list>
<item> First item outer </item>
<item> Second item outer </item>
<item>
<list>
<item> nested first </item>
</list>
</item>
<item> Third item outer </item>
</list>
</document>
Relax NG follows:
<grammar xmlns="http://relaxng.org/ns/structure/1.0">
<start>
<element name="document">
<oneOrMore>
<ref name="list-defn"/>
</oneOrMore>
</element>
</start>
<define name="list-defn">
<element name="list">
<oneOrMore>
<element name="item">
<choice>
<text />
<ref name="list-defn"/>
</choice>
</element>
</oneOrMore>
</element>
</define>
</grammar>
Here's what Trang makes of it (with blank lines inserted for ease of
reading).
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="document">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="list"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="list">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="item"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="item">
<xs:complexType mixed="true">
<xs:sequence>
<xs:element minOccurs="0" ref="list"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
But the "item" element is NOT mixed; if you make an item mixed as
follows, then it's invalid according to Relax NG, but not according to
XML Schema.
<item> some text and a...
<list>
<item>nested</item>
</list>
</item>
My questions are:
1) Can I write an XML Schema that will do exactly the same thing that
the Relax NG does?
2) If so, how many hoops must I jump through to accomplish it?
3) I'm sure Trang's output is reasonable, but I don't understand the
reasoning. Any simple explanations?
--
J. David Eisenberg http://catcode.com/
More information about the relaxng-user
mailing list