XML Schema中的唯一约束

假设我有以下 XML文件
<authors>
   <author>a1</author>
   <author>a2</author>
   <lastmodified>2010</lastmodified>
</authors>

和XML模式片段:

<xs:element name="authors" maxOccurs="1">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="author" maxOccurs="unbounded" type="xs:string"> </xs:element>
      <xs:element name="lastmodified" type="xs:date" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
  <xs:unique name="uniqueAuthor">
     <xs:selector xpath="."/>
     <xs:field xpath="author"/>
  </xs:unique>
</xs:element>

我想要的是制定一个不允许两个相同的作者值的约束,但上面的一个不会这样工作.我究竟做错了什么?

选择器XPath选择必须是唯一的节点(在这种情况下,它应该选择作者节点).字段XPath选择“使其独特”(在这种情况下,使用)将导致其类型值,在这种情况下,标签间的文本被视为字符串,被使用).文件
<?xml version="1.0" encoding="UTF-8"?>
<authors>
  <author>a1</author>
  <author>a2</author>
  <lastmodified>2010-01-01</lastmodified>
</authors>

应该对以下模式有效:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="authors">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="author" maxOccurs="unbounded" type="xs:string"/>
        <xs:element name="lastmodified" type="xs:date" minOccurs="0"/>
      </xs:sequence>
    </xs:complexType>
    <xs:unique name="uniqueAuthor">
      <xs:selector xpath="author"/>
      <xs:field xpath="."/>
    </xs:unique>
  </xs:element>
</xs:schema>

而这个不应该:

<?xml version="1.0" encoding="UTF-8"?>
<authors>
  <author>a1</author>
  <author>a1</author>
  <lastmodified>2010-01-01</lastmodified>
</authors>

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念