限制中的XSD ref元素替换

时间:2018-06-29 16:51:08

标签: validation xsd restriction

我遇到类型为MyC_COMPLEX_OBJECT_ATTRIBUTES_A ...无效限制的验证错误。我要执行的操作如下:我想从通用容器结构(C_COMPLEX_OBJECT)继承,并为每个容器设置一个具有特定结构(MyC_COMPLEX_OBJECT_A)和一组特定属性( MyC_COMPLEX_OBJECT_ATTRIBUTES_A)...

有人希望有办法解决这个问题吗? ...还是可以/应该更改通用结构吗?如果可以,怎么办?

注意:

A)我做block="extension"的原因是我要确保C_COMPLEX_OBJECT_ATTRIBUTES的子类型没有C_ATTRIBUTE以外的其他类型

B)我之所以没有创建C_ATTRIBUTE子元素(例如<xs:element name="value" type="MyC_ATTRIBUTE_A" substitutionGroup="C_ATTRIBUTE"/>,所以我要通过MyC_COMPLEX_OBJECT_ATTRIBUTES_A粘贴在ref="attributeA"中)的原因是,这些属性可以具有与一组派生的C_COMPLEX_OBJECTS同名...意味着可以有ObjectA.valueObjectB.value(后者的类型不同...->我以唯一身份运行粒子归因问题)

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns="http://blabla.com" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" targetNamespace="http://blabla.com" elementFormDefault="qualified" attributeFormDefault="unqualified" vc:minVersion="1.1">

<!-- predefined section -->
<xs:element name="C_ATTRIBUTE" type="C_ATTRIBUTE" abstract="true"/>    

<xs:complexType name="C_ATTRIBUTE" abstract="true" block="extension">
    <xs:attribute name="rm_attribute_name" type="xs:string" use="required"/>
    <xs:attribute name="is_multiple" type="xs:boolean" use="required"/>
</xs:complexType>
    
<xs:complexType name="C_COMPLEX_OBJECT" abstract="true" block="extension">
    <xs:sequence>
        <xs:element name="attributes" type="C_COMPLEX_OBJECT_ATTRIBUTES" minOccurs="0" maxOccurs="1"/>
    </xs:sequence>
</xs:complexType>

<xs:complexType name="C_COMPLEX_OBJECT_ATTRIBUTES" abstract="true" block="extension">
    <xs:sequence>
        <xs:element ref="C_ATTRIBUTE" minOccurs="1" maxOccurs="unbounded"/>
    </xs:sequence>
</xs:complexType>

<!-- Custom section -->
<xs:element name="MyObjectA" type="MyC_COMPLEX_OBJECT_A" />
<xs:element name="MyObjectB" type="MyC_COMPLEX_OBJECT_B" />


<xs:complexType name="MyC_COMPLEX_OBJECT_A">
    <xs:complexContent>
        <xs:restriction base="C_COMPLEX_OBJECT">
            <xs:sequence>
                <xs:element name="attributes" type="MyC_COMPLEX_OBJECT_ATTRIBUTES_A" minOccurs="0" maxOccurs="1" />
            </xs:sequence>
        </xs:restriction>
    </xs:complexContent>
</xs:complexType>

<xs:complexType name="MyC_COMPLEX_OBJECT_ATTRIBUTES_A">
    <xs:complexContent>
        <xs:restriction base="C_COMPLEX_OBJECT_ATTRIBUTES">
            <xs:sequence>
                <xs:element name="value" type="MyC_ATTRIBUTE_A"/>
            </xs:sequence>
        </xs:restriction>
    </xs:complexContent>
</xs:complexType>

<xs:complexType name="MyC_ATTRIBUTE_A">
    <xs:complexContent>
        <xs:restriction base="C_ATTRIBUTE">
            <xs:attribute name="rm_attribute_name" fixed="attribute_A" type="xs:string" use="required"/>
            <xs:attribute name="is_multiple" type="xs:boolean" use="required"/>                
        </xs:restriction>
    </xs:complexContent>
</xs:complexType>    

<xs:complexType name="MyC_COMPLEX_OBJECT_B">
    <xs:complexContent>
        <xs:restriction base="C_COMPLEX_OBJECT">
            <xs:sequence>
                <xs:element name="attributes" type="MyC_COMPLEX_OBJECT_ATTRIBUTES_B" minOccurs="0" maxOccurs="1" />
            </xs:sequence>
        </xs:restriction>
    </xs:complexContent>
</xs:complexType>

<xs:complexType name="MyC_COMPLEX_OBJECT_ATTRIBUTES_B">
    <xs:complexContent>
        <xs:restriction base="C_COMPLEX_OBJECT_ATTRIBUTES">
            <xs:sequence>
                <xs:element name="value" type="MyC_ATTRIBUTE_B"/>
                <xs:element name="sth_of_another_attribute_type" type="MyC_ATTRIBUTE_A"/>
            </xs:sequence>
        </xs:restriction>
    </xs:complexContent>
</xs:complexType>

<xs:complexType name="MyC_ATTRIBUTE_B">
    <xs:complexContent>
        <xs:restriction base="C_ATTRIBUTE">
            <xs:attribute name="rm_attribute_name" fixed="attribute_B" type="xs:string" use="required"/>
            <xs:attribute name="is_multiple" type="xs:boolean" use="required"/>                
        </xs:restriction>
    </xs:complexContent>
</xs:complexType>

</xs:schema>

0 个答案:

没有答案