Re: schema help needed (3 questions)

Hi,

> 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:simpleContent>
    <xs:extension base="xs:double">
      <xs:attribute name="value" type="xs:double" />
    </xs:extension>
  </xs:simpleContent>
</xs:complexType>

(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:simpleContent>
    <xs:restriction base="valueType">
      <xs:attribute name="value" default="0">
        <xs:simpleType>
          <xs:restriction base="xs:double">
            <xs:minInclusive value="-100000" />
            <xs:maxInclusive value="100000" />
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
    </xs:restriction>
  </xs:simpleContent>
</xs:complexType>

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" />
  </xs:restriction>
</xs:simpleType>

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:complexContent>
    <xs:restriction base="baseType">
      <xs:attribute name="that" type="someenum" fixed="specificenum"
      />
    </xs:restriction>
  </xs:complexContent>
</xs:complexType>

Cheers,

Jeni

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

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