0

我有以下 XSD,我需要向其中添加另一个唯一约束。

我想让 Name 在其父 Groups 元素中唯一,但是可以在每个 WikiMeta 中重复一个组。

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="AllMeta">
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="unbounded" name="WikiMeta">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="Subject" type="xs:string" minOccurs="1" maxOccurs="1" />
              <xs:element name="PageTitle" type="xs:string" minOccurs="1" maxOccurs="1" />
              <xs:element name="PageMetaDescription" type="xs:string" minOccurs="1" maxOccurs="1" />
              <xs:element name="Articles">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="WikiArticle" minOccurs="1" maxOccurs="unbounded">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element name="FileName" type="xs:string" minOccurs="1" maxOccurs="1" />
                        </xs:sequence>
                      </xs:complexType>
                      <xs:unique name="uniqueFileName">
                        <xs:selector xpath="WikiMeta"/>
                        <xs:field xpath="FileName"/>
                      </xs:unique>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <xs:element name="Groups">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element maxOccurs="unbounded" name="WikiGroup">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element name="Name" type="xs:string" minOccurs="1" maxOccurs="1" />
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
    <xs:unique name="subject">
      <xs:selector xpath="WikiMeta"/>
      <xs:field xpath="Subject"/>
    </xs:unique>
    <xs:unique name="fileName">
      <xs:selector xpath="WikiMeta/Articles/WikiArticle"/>
      <xs:field xpath="FileName"/>
    </xs:unique>
  </xs:element>
</xs:schema>

有任何想法吗?

4

1 回答 1

0

将约束添加到定义可见性级别的元素。这是修改后的 XSD:

<?xml version="1.0" encoding="utf-8" ?>
<!-- XML Schema generated by QTAssistant/XSD Module (http://www.paschidev.com) -->
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="AllMeta">
        <xs:complexType>
            <xs:sequence>
                <xs:element maxOccurs="unbounded" name="WikiMeta">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="Subject" type="xs:string" minOccurs="1" maxOccurs="1"/>
                            <xs:element name="PageTitle" type="xs:string" minOccurs="1" maxOccurs="1"/>
                            <xs:element name="PageMetaDescription" type="xs:string" minOccurs="1" maxOccurs="1"/>
                            <xs:element name="Articles">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element name="WikiArticle" minOccurs="1" maxOccurs="unbounded">
                                            <xs:complexType>
                                                <xs:sequence>
                                                    <xs:element name="FileName" type="xs:string" minOccurs="1" maxOccurs="1"/>
                                                </xs:sequence>
                                            </xs:complexType>
                                            <xs:unique name="uniqueFileName">
                                                <xs:selector xpath="WikiMeta"/>
                                                <xs:field xpath="FileName"/>
                                            </xs:unique>
                                        </xs:element>
                                    </xs:sequence>
                                </xs:complexType>
                            </xs:element>
                            <xs:element name="Groups">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element maxOccurs="unbounded" name="WikiGroup">
                                            <xs:complexType>
                                                <xs:sequence>
                                                    <xs:element name="Name" type="xs:string" minOccurs="1" maxOccurs="1"/>
                                                </xs:sequence>
                                            </xs:complexType>
                                        </xs:element>
                                    </xs:sequence>
                                </xs:complexType>
                                <xs:key name="groupkey">
                                    <xs:selector xpath="WikiGroup"/>
                                    <xs:field xpath="Name"/>
                                </xs:key>
                            </xs:element>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
        <xs:unique name="subject">
            <xs:selector xpath="WikiMeta"/>
            <xs:field xpath="Subject"/>
        </xs:unique>
        <xs:unique name="fileName">
            <xs:selector xpath="WikiMeta/Articles/WikiArticle"/>
            <xs:field xpath="FileName"/>
        </xs:unique>
    </xs:element>
</xs:schema>

视觉上可能更容易理解:

在此处输入图像描述

于 2013-10-24T13:35:51.107 回答