Вопрос

I'd like to suppress the use of an attribute (underline) inherited from a base schema (BaseSchema.xsd) without redefining the entire element TextType, if possible, in the manner demonstrated in the following example:

Base schema (BaseSchema.xsd)

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xs:element name="Text" type="TextType"/>
    <xs:complexType name="TextType"> <!-- Actual example is much longer -->
        <xs:attribute name="bold" type="xs:boolean"/>
        <xs:attribute name="italics" type="xs:boolean"/>
        <xs:attribute name="underline" type="xs:boolean"/>
    </xs:complexType>
</xs:schema>

Derived schema (DerivedSchema.xsd)

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xs:override schemaLocation="BaseSchema.xsd">
        <xs:complexType name="TextType">
            <xs:simpleContent>
                <xs:extension base="TextType">
                    <xs:attribute name="underline" type="xs:boolean" use="prohibited"/>                  
                </xs:extension>
            </xs:simpleContent>
        </xs:complexType>
    </xs:override>
</xs:schema>

The problem here is that TextType in <xs:extension base="TextType"> amounts to a circular definition, and I'd like to identify it as the TextType defined in the base schema.

Solution, based on xs:redefine thanks to Michael

Base schema (edited)

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xs:element name="Text" type="TextType"/>
    <xs:complexType name="TextType">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute name="bold" type="xs:boolean"/>
                <xs:attribute name="italics" type="xs:boolean"/>
                <xs:attribute name="underline" type="xs:boolean"/>                
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>
</xs:schema>

Derived schema (edited)

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xs:redefine schemaLocation="BaseSchema.xsd">
        <xs:complexType name="TextType">
            <xs:simpleContent>
                <xs:restriction base="TextType">
                    <xs:attribute name="underline" type="xs:boolean" use="prohibited"/> 
                </xs:restriction>
            </xs:simpleContent>
        </xs:complexType>
    </xs:redefine>
</xs:schema>
Это было полезно?

Решение

xs:override (unlike xs:redefine) doesn't allow you to define the new type by derivation from the old type, rather you define a replacement for the original type "from scratch". If you want to reduce the amount of stuff that's unnecessarily replicated in the new definition, use smaller-granularity components, e.g. define each of the attributes as a global attribute group, so you only need to override one of them. (But I have a feeling that defining an attribute as prohibited within an attribute group is ineffective, so that might not work.)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top