Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using xs:extension & xs:restriction together?

Tags:

xml

schema

xsd

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?

like image 581
oconnor0 Avatar asked Aug 05 '10 19:08

oconnor0


Video Answer


1 Answers

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)-->
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <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>
like image 75
Sprotty Avatar answered Sep 29 '22 05:09

Sprotty