Connecting Tech Pros Worldwide Forums | Help | Site Map

Wrapped recursive elements--"boxes and bags"

Newbie
 
Join Date: Dec 2006
Posts: 1
#1: Dec 2 '06
Hi,

I've been struggling to create a valid XML schema that implements the following innocent-looking concept:

A box may contain a bunch of bags (possibly 0).
A bag must contain a bunch of boxes (at least 1).


It seems like a simple extension on the well-known doll concept:
A doll may contain a bunch of dolls (possibly 0).
whose simple solution is, for example:
<xsd:element name="doll" type="dollType"/>
<xsd:complexType name="dollType">
<xsd:sequence>
<xsd:element ref="doll" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
The only difference with the boxes-and-bags problem is that bags are "wrappers" for the recursion on boxes. But in both cases, the recursion has an opportunity to terminate.

Every variation of this schema I've tried in VS2005 has failed, for example:
<xsd:element name="box" type="boxType"/>
<xsd:element name="bag" type="bagType"/>
<xsd:complexType name="boxType">
<xsd:sequence minOccurs="0" maxOccurs="unbounded">
<xsd:element ref="branch" minOccurs="0" maxOccurs="unbounded">
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="bagType">
<xsd:sequence>
<xsd:element ref="box" minOccurs="1" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>


Is what I'm attempting to do simply illicit or am I just missing something?

Thanks much,

Evan

Reply