Xsd 本地独特?

Xsd 本地独特?,xsd,Xsd,我试图弄清楚XML模式的唯一和关键元素, 特别是关于内的选择器和字段元素 我不清楚选择器和字段,我需要弄清楚这一点 假设我有一个XML文件,其中列出了功能组中的公司。 我在每个组中都有一个元素,具有唯一的字段(参考 每个特定组) 我想在中列出的每个公司中创建一个唯一的字段 只有在特定组中才唯一的每个组 这是正确的吗 <xs:unique id="company_group_refs" name="company_group_refs"> <xs:sele

我试图弄清楚XML模式的唯一和关键元素, 特别是关于内的选择器和字段元素

我不清楚选择器和字段,我需要弄清楚这一点

假设我有一个XML文件,其中列出了功能组中的公司。 我在每个组中都有一个元素,具有唯一的字段(参考 每个特定组)

我想在中列出的每个公司中创建一个唯一的字段 只有在特定组中才唯一的每个组

这是正确的吗

    <xs:unique id="company_group_refs" name="company_group_refs">
        <xs:selector xpath="root/all_companies/company_group"/>
        <xs:field xpath="company_group_ref"/>
    </xs:unique>

    <xs:unique id="company_refs" name="company_refs">
        <xs:selector xpath="root/all_companies/company_group"/>
        <xs:field xpath="company/company_ref"/>
    </xs:unique>

如果是这样的话,我能把上面的内容浓缩成这样吗

    <xs:unique id="company_refs" name="company_refs">
        <xs:selector xpath="root/all_companies/company_group"/>
        <xs:field xpath="company_group_ref"/>
        <xs:field xpath="company/company_ref"/>
    </xs:unique>

要特别提及任何公司名称,我希望能够 给出如下XPath表达式:

根目录/所有公司/公司集团[公司集团\u ref=x1]/公司[公司\u ref=x2]/名称

其中:x1=公司集团的唯一参考。
和:x2=该集团内公司的唯一参考

下面是一个XML文件摘录,举例说明了这种情况:

<all_companies>

    <company_group>
        <company_group_name>Cleaning</company_group_name>
        <company_group_ref>1</company_group_ref>
        <company>
            <name>Ajax</name>
            <company_ref>1</company_ref>
        </company>
        <company>
            <name>Bloomburg</name>
            <company_ref>2</company_ref>
        </company>
        <company>
            <name>Morris</name>
            <company_ref>3</company_ref>
        </company>
    </company_group>

    <company_group>
        <company_group_name>Electrical</company_group_name>
        <company_group_ref>2</company_group_ref>
        <company>
            <name>Armstrong</name>
            <company_ref>1</company_ref>
        </company>
        <company>
            <name>Bloomburg</name>
            <company_ref>2</company_ref>
        </company>
        <company>
            <name>Zap Electrical</name>
            <company_ref>3</company_ref>
        </company>
        <company>
            <name>Morris</name>
            <company_ref>4</company_ref>
        </company>
    </company_group>

</all_companies>

打扫
1.
AJAX
1.
布卢姆堡
2.
莫里斯
3.
与电有关的
2.
阿姆斯特朗
1.
布卢姆堡
2.
扎普电气
3.
莫里斯
4.

谢谢

您要求组参考的唯一性的约束是正确的。使公司参考在组中唯一的约束应如下所示

<xs:element name="company_group">
  <xs:unique name="company_unique_within_group">
    <xs:selector xpath="company">
    <xs:field xpath="company_ref">
  </xs:unique>
  ...
</xs:element>

...
将其理解为“在公司集团内”“选择所有公司”,并要求“公司参考在这些公司中是唯一的”

您的公司参考约束规定:“全球范围内”“对于所有公司组”要求“公司/公司参考是唯一的”


您的压缩约束表达了完全不同的内容:“全局”“对于所有公司集团”“要求公司集团参考和公司/公司参考的组合”是唯一的“。考虑到每个小组实际上有多个公司参考,后两个是毫无意义的。

嗨,马丁!谢谢你的回复和答案。这是有道理的。