XSD Schema: complexType or Group?

  • Thread starter unishippers.suckfeed.newshosting.com
  • Start date
U

unishippers.suckfeed.newshosting.com

Thanks for the response, Priscilla, it was very useful,

Now: what if I want to have an empty group that will only contain atomic
sub elements of the containing type:

<object>
<things>
<thing>
1
</thing>
<thing>
2
</thing>
<thing>
3
</thing>
</things>
</object>

How would this be best expressed? Would the "things" element be a
complexType, or a group, or something else? What should it be if it only
contains instances of the group moniker class?

Thanks,

Jason Hodge
 
P

Priscilla Walmsley

Hi Jason,

Every element that can contain other elements has to have a complex
type. So you would definitely need complex types for "object" and
"things". For example:

<xs:element name="object" type="objectType"/>
<xs:complexType name="objectType">
<xs:sequence>
<xs:element name="things" type="thingsType"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="thingsType">
<xs:sequence>
<xs:element name="thing" type="xs:integer"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>

Groups (i.e. xs:group elements) are used when you want to reuse pieces
of the content model in more than one complex type. For example, if
every "product" element had a name, number and description (among other
children), and every "warehouse" element had the same 3 children, plus
some other warehouse-specific things. You could create a group that is
comprised of name, number and description, then refer to that group from
the complex types of both the "product" and "warehouse" elements.

Hope that helps,
Priscilla
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top