Re: simple schema Q

Hi Sam,

> I have a very simply scema Q. I am defining a menu in XML and trying
> to get the schema put together for it. The problem I am having is
> that a menu must have at least one item element and can have zero or
> more itemSep<arators> elements. I cannot figure out how to layout
> the schema for this. What I have currently is:
>
> <xs:complexType name="menuItem">
>   <xs:choice>
>     <xs:element name="item" type="itemItem" maxOccurs="unbounded"/>
>     <xs:element name="itemSep" type="itemSepItem" minOccurs="0" maxOccurs="unbounded"/>
>   </xs:choice>
>   <xs:attribute name="id" type="xs:string" use="required"/>
> </xs:complexType>

That won't work, because it means that you *either* have one or more
<item> elements *or* zero or more <itemSep> elements. Assuming that
you don't want <itemSep> elements to appear next to each other, and
that you want an <item> element to be the first thing in the menu, I
think that you want:

<xs:complexType name="menuItem">
  <xs:sequence maxOccurs="unbounded">
    <xs:element name="item" type="itemItem" />
    <xs:element name="itemSep" type="itemSepItem" minOccurs="0" />
  </xs:sequence>
  <xs:attribute name="id" type="xs:string" use="required" />
</xs:complexType>

If you just want to say one-or-more <item> elements and zero-or-more
<itemSep> elements in any order, then use the XML Schema equivalent of
the content model:

  (itemSep*, item, (item | itemSep)*)

> P.S. As you can tell, I name my types based on the element name then
> tag Item onto the end. Is there a standard that I could adopt? Or at
> least a better way of doing this?

The convention that I've seen used most frequently is to append "Type"
at the end, e.g. menuType, itemType, itemSepType. Personally, I prefer
not to use a postfix since the names of elements and those of types
can't clash anyway.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

Received on Monday, 3 March 2003 05:29:22 UTC