假设我有以下 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>
所以看起来第一个词按预期工作,但不是第二个......