xml schema - restricted element content together with attributes

What is the best practice for an XML schema describing an element with one or more
attributes plus data content, where the data content is not a supplied data type and
neither is it shared by other tags?

For example:

<tag1 attr="value1">some data</tag1>
<tag2 attr="value2">other data</tag2>

where I would like to describe each <tag> content something like

<xsd:restriction>
    <xsd:enumeration value="red"/>
    <xsd:enumeration value="blue"/>
    <xsd:enumeration value="green"/>
</xsd:restriction>

The short question is simply: what's the preferred way to do that?

The separate longer question is more specific.  In my particular case, there are many
different elements, each with a different description of the data content.  There are only
a small number of different attributes, where the same attribute could be used by several
elements.  It happens that the attribute definition is loosely related to the value's base type
(that is, the data content of all elements using a certain attribute might be based on
xsd:string, the data content of all elements using a certain other attribute might be based
on xsd:int, etc.)

That suggests to me that I should create my own base types, one for each attribute, that
describe both the attribute and the base type of the data content.  Then my element
definitions would be derived and further restrict the data content.  I can't figure out how
to do that.

So here's the exercise for the interested, what's the most efficient XML schema for
something like this, understanding that there are many more elements and maybe a few
more attributes:

element A accepts attribute "text" and string data "red", "blue", "green".
element B accepts attribute "text" and string data with a length less than 5.
element C accepts attribute "number" and numeric data between 100 and 200.
element D accepts attribute "number" and numeric data between 1 and 10.

Thanks,
Lee

Received on Friday, 11 June 2004 19:37:30 UTC