如何对一组属性进行 XSD 限制

how to put XSD restriction on a group of attributes

我关注XSD.

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="a">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="b">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element maxOccurs="unbounded" name="c">
                            <xs:complexType>
                                <xs:attribute name="id" use="required" >
                                    <xs:simpleType>
                                        <xs:restriction base="xs:string">
                                            <xs:enumeration value="1"/>
                                            <xs:enumeration value="2"/>
                                        </xs:restriction>
                                    </xs:simpleType>
                                </xs:attribute>
                                <xs:attribute name="name" use="required" >
                                    <xs:simpleType>
                                        <xs:restriction base="xs:string">
                                            <xs:enumeration value="AA"/>
                                            <xs:enumeration value="BB"/>
                                        </xs:restriction>
                                    </xs:simpleType>
                                </xs:attribute>
                            </xs:complexType>
                        </xs:element>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>
</xs:schema>

这对

有效
<?xml version="1.0" encoding="UTF-8" ?>
<a>
    <b>
        <c id="1" name="AA"/>
        <c id="2" name="BB"/>
    </b>
</a>

但我想编写一个架构文档来限制所有属性组合中的值。为进一步说明,上述 XSD 也适用于以下 XML。

<?xml version="1.0" encoding="UTF-8" ?>
<a>
    <b>
        <c id="2" name="AA"/>
        <c id="2" name="BB"/>
    </b>
</a>

<?xml version="1.0" encoding="UTF-8" ?>
<a>
    <b>
        <c id="1" name="AA"/>
        <c id="1" name="BB"/>
    </b>
</a>

<?xml version="1.0" encoding="UTF-8" ?>
<a>
    <b>
        <c id="1" name="BB"/>
        <c id="2" name="BB"/>
    </b>
</a>

但我想将其限制为组值,例如, 它应该对第一个示例有效,但对任何其他示例无效 [​​=23=]。有什么办法吗?

<?xml version="1.0" encoding="UTF-8" ?>
<a>
    <b>
        <c id="1" name="AA"/>
        <c id="2" name="BB"/>
    </b>
</a>

我不太擅长从少量示例中得出一般规则。但总的原则是,要编写属性组合的规则,需要XSD 1.1 断言。有几个模式处理器支持 XSD 1.1 和断言,但也有一些不支持,所以你必须做出决定。