我的XSD架构出了什么问题?

时间:2014-08-18 09:46:13

标签: xml xsd

这是架构:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:complexType name="entry">
    <xs:attribute name="key" type="xs:string" use="required"/>
  </xs:complexType>
  <xs:element name="p">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="entry" minOccurs="0" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

此XML应该无法针对此架构进行验证,因为错过了key属性:

<p><entry/></p>

但它并没有失败。我做错了什么?

1 个答案:

答案 0 :(得分:1)

name元素定义中的entry属性未链接到类型定义。

您只需在entry元素定义中添加对该类型的引用(以便有效地键入它):

<xs:element type="entry" name="entry" minOccurs="0" maxOccurs="unbounded"/>
相关问题