我无法让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>
为什么我的重复参考值没有出错? Arrrggghhh!我已经阅读了互联网上的所有内容.请帮助别人.
解决方法
用这个:
<?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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。