gpt4 book ai didi

xml - 如何在 XML 架构中指定唯一值

转载 作者:数据小太阳 更新时间:2023-10-29 01:56:44 26 4
gpt4 key购买 nike

我无法让 xs:unique 说明符在 XML 文件中工作。我似乎无法计算出有效的 XPath。对于这个问题中的代码量,我深表歉意,但我将非常感谢任何能在下面指出我做错了什么的人。无论我做什么,我都无法获取元素中的@ref 属性来报告我复制值的错误(每个 ref 必须是唯一的)。

如能提供任何帮助或信息提示,我们将不胜感激。

祝你好运

这是我的模式:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="Artworks"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:aw="http://www.fourthwish.co.uk/data/Artworks.xsd"
xmlns="http://www.fourthwish.co.uk/data/Artworks.xsd"
targetNamespace="http://www.fourthwish.co.uk/data/Artworks.xsd"
elementFormDefault="qualified"
>
<xs:element name="artworks">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="artwork" type="ArtworkType">
<xs:unique name="uniqueRef">
<xs:selector xpath="artwork"/>
<xs:field xpath="@ref"/>
</xs:unique>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="ArtworkType">
<xs:sequence>
<xs:element name="title" type="xs:string"/>
</xs:sequence>
<xs:attribute name="ref" type="xs:nonNegativeInteger"/>
</xs:complexType>
</xs:schema>

这是我的 XML 文件:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<artworks
xmlns="http://www.fourthwish.co.uk/data/Artworks.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.fourthwish.co.uk/data/Artworks.xsd Artworks.xsd"
>
<artwork ref="1">
<title>Title String</title>
</artwork>
<artwork ref="1">
<title>Title String</title>
</artwork>
</artworks>

为什么我没有收到重复引用值的错误消息?啊啊啊!我已经阅读了互联网上的所有内容。请帮助某人。

最佳答案

使用这个:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="Artworks"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:aw="http://www.fourthwish.co.uk/data/Artworks.xsd"
xmlns="http://www.fourthwish.co.uk/data/Artworks.xsd"
targetNamespace="http://www.fourthwish.co.uk/data/Artworks.xsd"
elementFormDefault="qualified"
>
<xs:element name="artworks">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="artwork" type="ArtworkType"/>
</xs:sequence>
</xs:complexType>

<xs:unique name="uniqueRef">
<xs:selector xpath="aw:artwork"/>
<xs:field xpath="@ref"/>
</xs:unique>

</xs:element>

<xs:complexType name="ArtworkType">
<xs:sequence>
<xs:element name="title" type="xs:string"/>
</xs:sequence>
<xs:attribute name="ref" type="xs:nonNegativeInteger"/>
</xs:complexType>
</xs:schema>

关于xml - 如何在 XML 架构中指定唯一值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7835600/

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