You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Jim Puccio <ch...@earthlink.net> on 2000/10/10 10:48:32 UTC
Validating schemas with recursive types
I am trying to make a schema for a grammar that, in its most stripped-down
version, looks like
tree := <list> [ tree ]* </list> | <leaf/>
I am totally baffled as to how to accomplish this, though I've been able to
make one for the verbose variant
tree := <list> [ <item> tree </item> ]* </list> | <leaf/>
as follows:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
xmlns:xsd = "http://www.w3.org/1999/XMLSchema"
xmlns:xsi = "http://www.w3.org/1999/XMLSchema-instance">
<xsd:complexType name = "tree">
<xsd:choice>
<xsd:element name = "node">
<xsd:complexType>
<xsd:element name = "item" type = "tree" minOccurs = "0"
maxOccurs = "unbounded"/>
</xsd:complexType>
</xsd:element>
<xsd:element name = "leaf"/>
</xsd:choice>
</xsd:complexType>
<xsd:element name = "root" type = "tree"/>
</xsd:schema>
This does just fine parsing an instance document that looks like
<?xml version="1.0" encoding="UTF-8"?>
<root
xmlns:xsi = "http://www.w3.org/1999/XMLSchema-instance"
xsi:noNamespaceSchemaLocation = "adapter.xsd">
<node>
<item><leaf/></item>
<item><leaf/></item>
<item>
<node>
<item><leaf/></item>
</node>
</item>
</node>
</root>
but all those <item>s are really obnoxious, and what we really want is to be
able to parse the terser structure
<?xml version="1.0" encoding="UTF-8"?>
<root
xmlns:xsi = "http://www.w3.org/1999/XMLSchema-instance"
xsi:noNamespaceSchemaLocation = "adapter.xsd">
<node>
<leaf/>
<leaf/>
<node><leaf/></node>
</node>
</root>
instead. I've been struggling with abstract types and equivalence classes,
trying to accomplish this, but to no avail. Am I trying to do something
that XML has been designed to prevent? If there is a way to do what I want,
could someone please help me to understand how to accomplish it? The
relevant examples that I have to work from, in Box, Skonnard & Lam's book,
David Hunter's book, and the XML Schema Working Draft (Sep 2000) all fail
for one reason or another on Xerces 1.2.0, which is what I am using.
Thanks in advance,
-- Jim Puccio