0

I have the a little problem with the xsd below. I have created a type of vaultobject with a type attribute that can have any value in a enumeration. Then I derived VaultServiceObject from vaultobject en set a restriction to limit type to a fixed value for the derived object.

The editor (liquid-xml) design service seems to understand this and displays correctly, but the text editor marks the line 26 as and error.

<xs:attribute name="Type" fixed="ServiceConfiguration" type="xs:string" use="required">

Saying "Error Invalid attribute restriction. Derived attribute's type is not a valid restriction of the base attribute's type." So from this I guess "xs:string" is wrong. But I cannot figure out what type I should use.

Hopefully there is someone more experienced with XSD out there.

p.s I cobbled xsd below together from several other similar stackoverflow questions, but they do not supply this exact combination and its solution. So please do not point to those without explaining what I am looking for.

<?xml version="1.0" encoding="utf-8" ?>
<!--Created with Liquid Studio 2020 (https://www.liquid-technologies.com)-->
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:complexType name="VaultObject">
        <xs:sequence>
            <xs:annotation>
                <xs:documentation>Allows for derived object to have a sequence of elements</xs:documentation>
            </xs:annotation>
        </xs:sequence>
        <xs:attribute name="Type" use="required">
            <xs:annotation>
                <xs:documentation>This is the list of possible vault objects. Derived objects need to lock this down to the object type the represent.</xs:documentation>
            </xs:annotation>
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:enumeration value="Merge" />
                    <xs:enumeration value="ServiceConfiguration" />
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>
        <xs:anyAttribute />
    </xs:complexType>
    <xs:complexType name="VaultServiceConfigurationObject">
        <xs:complexContent>
            <xs:restriction xmlns:q2="http://www.it-workz.nl/IDM" base="VaultObject">
                <xs:attribute name="Type" fixed="ServiceConfiguration" type="xs:string" use="required">
                    <xs:annotation>
                        <xs:documentation xml:lang="EN">This property is inherited from VaultObject, but is locked down to the fixed value of "ServiceConfiguration"</xs:documentation>
                    </xs:annotation>
                </xs:attribute>
                <xs:attribute name="ServiceType">
                    <xs:annotation>
                        <xs:documentation xml:lang="EN">The list of possible service types we support. Derived service definitions need to lock this down to a single value in their own type.</xs:documentation>
                    </xs:annotation>
                    <xs:simpleType>
                        <xs:restriction base="xs:string">
                            <xs:enumeration value="SystemA" />
                            <xs:enumeration value="SystemB" />
                        </xs:restriction>
                    </xs:simpleType>
                </xs:attribute>
                <xs:attribute name="Name" type="xs:string" use="required">
                    <xs:annotation>
                        <xs:documentation xml:lang="EN">Every service needs to be uniquely named. Even between different service types.</xs:documentation>
                    </xs:annotation>
                </xs:attribute>
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
</xs:schema>
zu1b
  • 422
  • 5
  • 11

1 Answers1

0

You can do this by breaking the 'Type' enum out into it's own SimpleType.

<?xml version="1.0" encoding="utf-8" ?>
<!--Created with Liquid Studio 2020 (https://www.liquid-technologies.com)-->
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:simpleType name="VaultObjectType">
        <xs:restriction base="xs:string">
            <xs:enumeration value="Merge" />
            <xs:enumeration value="ServiceConfiguration" />
        </xs:restriction>
    </xs:simpleType>
    <xs:complexType name="VaultObject">
        <xs:sequence>
            <xs:annotation>
                <xs:documentation>Allows for derived object to have a sequence of elements</xs:documentation>
            </xs:annotation>
        </xs:sequence>
        <xs:attribute name="Type" type="VaultObjectType" use="required">
            <xs:annotation>
                <xs:documentation>This is the list of possible vault objects. Derived objects need to lock this down to the object type the represent.</xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:anyAttribute />
    </xs:complexType>
    <xs:complexType name="VaultServiceConfigurationObject">
        <xs:complexContent>
            <xs:restriction xmlns:q2="http://www.it-workz.nl/IDM" base="VaultObject">
                <xs:attribute name="Type" fixed="ServiceConfiguration" type="VaultObjectType" use="required">
                    <xs:annotation>
                        <xs:documentation xml:lang="EN">This property is inherited from VaultObject, but is locked down to the fixed value of "ServiceConfiguration"</xs:documentation>
                    </xs:annotation>
                </xs:attribute>
                <xs:attribute name="ServiceType">
                    <xs:annotation>
                        <xs:documentation xml:lang="EN">The list of possible service types we support. Derived service definitions need to lock this down to a single value in their own type.</xs:documentation>
                    </xs:annotation>
                    <xs:simpleType>
                        <xs:restriction base="xs:string">
                            <xs:enumeration value="SystemA" />
                            <xs:enumeration value="SystemB" />
                        </xs:restriction>
                    </xs:simpleType>
                </xs:attribute>
                <xs:attribute name="Name" type="xs:string" use="required">
                    <xs:annotation>
                        <xs:documentation xml:lang="EN">Every service needs to be uniquely named. Even between different service types.</xs:documentation>
                    </xs:annotation>
                </xs:attribute>
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
</xs:schema>