views:

53

answers:

1

While writing an XML schema, I am attempting to do something like this

<xs:complexType name="ValueWithUnits">
    <xs:simpleContent>
        <xs:extension base="xs:double">
            <xs:attribute name="uom" fixed="second"/>
            <xs:minInclusive="0"/>
            <xs:maxInclusive="10"/>
        </xs:extension>
    </xs:simpleContent>
</xs:complexType>

Unfortunately, xs:attribute is allowed on xs:extension while xs:minInclusive & xs:maxInclusive are allowed on xs:restriction, but not together.

What is the best way to structure this? Do I have to define an extension with the appropriate units & then restrict it with my min & max values?

+1  A: 

You need to define the restriction on the double separatley

<?xml version="1.0" encoding="utf-8" ?>
<!--Created with Liquid XML Studio Developer Edition 8.1.4.2482 (http://www.liquid-technologies.com)--&gt;
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
    <xs:simpleType name="RestrictedDouble">
        <xs:restriction base="xs:double">
            <xs:minInclusive value="0" />
            <xs:maxInclusive value="10" />
        </xs:restriction>
    </xs:simpleType>
    <xs:complexType name="ValueWithUnits">
        <xs:simpleContent>
            <xs:extension base="RestrictedDouble">
                <xs:attribute name="uom" fixed="second" />
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>
</xs:schema>
Sprotty
oconnor0