【问题标题】:Problem with restriction in xsd complex type inheritancexsd复杂类型继承中的限制问题
【发布时间】:2020-10-30 10:23:16
【问题描述】:

我对下面的 xsd 有一点问题。我创建了一种类型的 Vaultobject,其类型属性可以在枚举中具有任何值。然后我从 VaultObject 派生 VaultServiceObject 并设置限制以将派生对象的类型限制为固定值。

编辑器 (liquid-xml) 设计服务似乎理解这一点并正确显示,但文本编辑器将第 26 行标记为错误。

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

说“错误无效的属性限制。派生属性的类型不是对基本属性类型的有效限制。”所以从这里我猜“xs:string”是错误的。但我不知道我应该使用哪种类型。

希望有人对 XSD 更有经验。

p.s 我从其他几个类似的 stackoverflow 问题拼凑了下面的 xsd,但它们没有提供这种确切的组合及其解决方案。所以请不要在没有解释我在寻找什么的情况下指向那些。

<?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>

【问题讨论】:

    标签: xsd liquid-xml


    【解决方案1】:

    您可以通过将“类型”枚举分解为它自己的 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>
    

    【讨论】:

      猜你喜欢
      • 2015-07-11
      • 2011-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-16
      • 2020-04-21
      • 2012-04-19
      • 1970-01-01
      相关资源
      最近更新 更多