Tôi không thể lấy xs: unique specifier để làm việc trong một tệp XML. Tôi dường như không thể tìm ra XPath hoạt động được. Tôi xin lỗi về số lượng mã trong câu hỏi này, nhưng tôi sẽ vô cùng biết ơn bất cứ ai có thể chỉ ra những gì tôi đang làm sai dưới đây. Không có vấn đề gì tôi làm, tôi không thể có được thuộc tính @ref trong phần tử để báo cáo lỗi cho việc sao chép giá trị của tôi (mỗi ref phải là duy nhất).Cách chỉ định các giá trị duy nhất trong lược đồ XML
Bất kỳ trợ giúp hoặc chỉ dẫn nào về thông tin sẽ rất biết ơn đã nhận được.
Kind muốn, Patrick
Đây là schema của tôi:
<?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>
Và đây là tập tin XML của tôi:
<?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>
Tại sao tôi không nhận được một lỗi cho ref trùng lặp giá trị? Arrrggghhh! Tôi đã đọc mọi thứ trên internet. Xin hãy giúp ai đó.