W3C home > Mailing lists > Public > xmlschema-dev@w3.org > December 2001

Re: schema help needed (3 questions)

From: Jeni Tennison <jeni@jenitennison.com>
Date: Fri, 7 Dec 2001 10:29:44 +0000
Message-ID: <45245618490.20011207102944@jenitennison.com>
To: sk ask <arigapudi_s@yahoo.com>
CC: xmlschema-dev@w3.org

> I have lots of elements like that below. So, I would like to define
> a type and reuse it. Not sure how to give different values to min
> and max Exclusive facets each time. Is it possible to do that?

Not without more-or-less repeating the same attribute declaration
every time. You could create a complex type that included a value
attribute with an xs:double type with no restrictions on it:

<xs:complexType name="valueType">
    <xs:extension base="xs:double">
      <xs:attribute name="value" type="xs:double" />

(Note that you have to derive by extension to get a complex type with
simple content and an attribute on it.)

Then you could create restrictions of that complex type in which each
attribute had a restricted set of values for the attribute:

<xs:complexType name="elevationType">
    <xs:restriction base="valueType">
      <xs:attribute name="value" default="0">
          <xs:restriction base="xs:double">
            <xs:minInclusive value="-100000" />
            <xs:maxInclusive value="100000" />

But it would be the same amount of code (actually more!) that you
would have if you defined them individually.

> 2) How to simulate a c/c++ enum in schema.
> I would like the named constants to be A,B,C.
> My attempt obviously fails:
> <simpleType name="some">
>  <restriction base="xsd:short"> <!-- ofcourse xsd:string will work -->
>    <enumeration value="A"/>
>    <enumeration value="B"/>
>    <enumeration value="C"/>
>  </restriction>
> </simpleType>

Sorry, I don't know what a c/c++ enum looks like - it appears that you
mean an association between a letter code and a number? I'd probably
use something like:

<xs:simpleType name="some">
  <xs:restriction base="xs:token">
    <xs:enumeration value="A" my:value="1" />
    <xs:enumeration value="B" my:value="2" />
    <xs:enumeration value="C" my:value="3" />

The schema validator would check whether elements or attribute of
'some' type had the values 'A', 'B' or 'C'. You would have to write
your own code to extract the values of the my:value attribute that
holds the numeric value for each code.

> 3)Is it possible to declare an attribute in an abstract base class
> that will be fixed in the derived schema (so, it doen't need to
> appear in the xml instance)?
> Thanks for any info/pointers.
> Example:
>  <complexType name="baseType"
>     <attribute name="that" type="someenum"/>
>  >
> <complexType name="derivedType">
>   <complexContent>
>     <extension base="baseType">
>       <attribute name="that" type="someenum"
> fixed="specficenum"/>
>     </extension>
>   </complexContent>
> </complexType>

You have to derive by restriction to do this, because you're limiting
the values of the attribute, not extending them. So you need:

<xs:complexType name="derivedType">
    <xs:restriction base="baseType">
      <xs:attribute name="that" type="someenum" fixed="specificenum"



Jeni Tennison
Received on Friday, 7 December 2001 05:29:45 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:14:56 UTC