18
我希望確保有下面的XML沒有重複的書名:如何確保XML模式中的唯一元素值?
<?xml version="1.0" encoding="UTF-8"?>
<books xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="books3.xsd">
<book>
<title>Book1</title>
</book>
<book>
<title>Book2</title>
</book>
<book>
<title>Book1</title> <!-- duplicate should not be allowed -->
</book>
</books>
我現在用的是以下模式:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="books">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="book"/>
</xs:sequence>
</xs:complexType>
<xs:unique name="testUnique">
<xs:selector xpath="book"/>
<xs:field xpath="title"/>
</xs:unique>
</xs:element>
<xs:element name="book">
<xs:complexType>
<xs:sequence>
<xs:element ref="title"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="title" type="xs:NCName"/>
</xs:schema>
氧XML編輯告訴我,這是有效的,當我確認。
有人可以看到我在做什麼錯嗎?
乾杯。無論我在氧氣中重新驗證了多少次,它都不會顯示錯誤。但是當我重啓Oxygen時,它會拋出上面的驗證錯誤。 – 2010-03-05 13:21:01