【发布时间】:2017-01-15 21:02:23
【问题描述】:
假设我有以下 XML:
<wordlist>
<language>English</language>
<author>John Smith</author>
<words>
<word id="0">Point</word>
<word id="1">Triangle</word>
<word id="2">Apple</word>
<word id="3">Plate</word>
<word id="4">Mango</word>
<word id="5">Computer</word>
</words>
</wordlist>
并希望为其创建 XSD 架构。
由于某种原因,我无法正确定义 <word> 元素。到目前为止,我想出的是:
<xs:element name="wordlist">
<xs:complexType>
<xs:sequence>
<xs:element name="language" type="xs:string" />
<xs:element name="author" type="xs:string" />
<xs:element name="words">
<xs:complexType>
<xs:sequence>
<xs:element name="word">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="id" type="xs:integer" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
但是当我运行时
xmllint -noout -schema wordlist.xsd
我明白了
dictionary.xml:11: element word: Schemas validity error : Element 'word': This element is not expected.
dictionary.xml fails to validate
第 11 行是
<word id="1">Triangle</word>
所以看起来第一个词按预期工作,但不是第二个......
【问题讨论】:
标签: xml xsd schema xml-validation xmlschemaset