gpt4 book ai didi

xml - 如何在 XML 模式中正确使用 unique 和 keyref?

转载 作者:数据小太阳 更新时间:2023-10-29 02:06:29 25 4
gpt4 key购买 nike

我有这个 XML 架构,但我不知道如何完成它才能实现我的需要。我在网上搜索了很多关于 unique 和 keyref 用法的信息,但我能找到的都是基本示例。

这是我的架构:

    <xs:element name="access" type="myaccess" />

<xs:complexType name="myaccess">
<xs:sequence>
<xs:element name="user" type="myuser" minOccurs="0" maxOccurs="unbounded">
<xs:unique name="u_idunique">
<xs:selector xpath="user" />
<xs:field xpath="@id" />
</xs:unique>
</xs:element>
<xs:element name="authorization" type="myauthorization" minOccurs="0" maxOccurs="unbounded">

<!-- HERE I WANT A KEYREF TO id attribute of user element -->
<!-- HERE I WANT A KEYREF TO id attribute of building element OR door element -->

</xs:element>
<xs:element name="building" type="mybuilding" minOccurs="0" maxOccurs="unbounded" >
<!-- I DON'T KNOW HOW TO SPECIFY THAT id of building, id of door and id of gate are in the same scope -->
<xs:unique name="b_idunique">
<xs:selector xpath="building" />
<xs:field xpath="@id" />
</xs:unique>
</xs:element>
</xs:sequence>
</xs:complexType>

<xs:complexType name="myuser">
<xs:attribute name="id" type="my_id" use="required" />
<xs:attribute name="name" type="xs:string" use="required" />
<xs:attribute name="phone" type="my_string_numeric" use="required" />
</xs:complexType>

<xs:complexType name="mybuilding">
<xs:sequence>
<xs:element name="door" type="mydoor" minOccurs="0" maxOccurs="unbounded">
<!-- I DON'T KNOW HOW TO SPECIFY THAT id of building, id of door and id of gate are in the same scope -->
<xs:unique name="d_idunique">
<xs:selector xpath="door" />
<xs:field xpath="@id" />
</xs:unique>
</xs:element>
</xs:sequence>
<xs:attribute name="id" type="my_id" use="required" />
<xs:attribute name="name" type="xs:string" use="required" />
<xs:attribute name="country" type="xs:string" use="required" />
</xs:complexType>

<xs:complexType name="mydoor">
<xs:sequence>
<xs:element name="gate" type="mygate" maxOccurs="unbounded">
<!-- I DON'T KNOW HOW TO SPECIFY THAT id of building, id of door and id of gate are in the same scope -->
<xs:unique name="g_idunique">
<xs:selector xpath="gate" />
<xs:field xpath="@id" />
</xs:unique>
</xs:element>
</xs:sequence>
<xs:attribute name="id" type="my_id" use="required" />
<xs:attribute name="address" type="xs:string" use="required" />
<xs:attribute name="status" type="mystatus" default="DISABLED" />
</xs:complexType>

<xs:complexType name="mygate">
<xs:attribute name="id" type="my_id" use="required" />
<xs:attribute name="type" type="mytype" use="required" />
<xs:attribute name="status" type="mystatus" default="DISABLED" />
</xs:complexType>

<xs:complexType name="myauthorization">
<xs:sequence>
<xs:element name="validityperiod" type="myvalidityperiod" />
</xs:sequence>
<xs:attribute name="idu" type="my_id" use="required" />
<xs:attribute name="idao" type="my_id" use="required" />
</xs:complexType>

<!-- OMITTED USELESS PART OF THE SCHEMA -->

</xs:schema>

我有两个问题:

  • 我不知道如何指定 building 的 id 字段、door 的 id 字段和 gate 的 id 字段在同一范围内,我不能有 2 个 id 相等(两个 building 不能有相同的id,但门和建筑物不能共享相同的id)
  • 我不知道如何正确使用 keyref 元素。
    1. 我希望授权元素的 IDU 字段是存在于用户元素之一中的 ID(请参阅下面的 [*])。
    2. 我希望授权元素的 idao 字段是一个存在于建筑元素之一或门元素之一中的 id。

[*] 我试着写这个,但它不起作用:

<xs:keyref name="useridkeyref" refer="u_idunique">
<xs:selector xpath="authorization" />
<xs:field xpath="@idu" />
</xs:keyref>

我知道这不是一个简短的问题,我提前感谢大家阅读它。我希望我能得到一些帮助。谢谢!

最佳答案

唯一约束和键在 element 级别范围内 - 您需要将约束放在不是每个单独元素内,而是放在作为共同祖先的 access 元素内所有这些。

<xs:element name="access" type="myaccess">
<xs:key name="user_id">
<xs:selector xpath="user" />
<xs:field xpath="@id" />
</xs:key>
<xs:key name="access_id">
<xs:selector xpath="building | building/door | building/door/gate" />
<xs:field xpath="@id" />
</xs:key>
<xs:keyref name="user_ref" refer="user_id">
<xs:selector xpath="authorization" />
<xs:field xpath="@idu" />
</xs:keyref>
<xs:keyref name="access_ref" refer="access_id">
<xs:selector xpath="authorization" />
<xs:field xpath="@idao" />
</xs:keyref>
</xs:element>

关于xml - 如何在 XML 模式中正确使用 unique 和 keyref?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20662664/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com