[英]XSD schema for a list of elements containing text and having attributes?
Let's say I have the following XML: 假设我有以下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>
and want to create an XSD schema for it. 并希望为其创建XSD架构。
I can't get the definition for the <word>
elements right for some reason. 由于某些原因,我无法正确定义<word>
元素。 What I've come up with so far is: 到目前为止,我想出的是:
<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>
but when I run 但是当我跑步时
xmllint -noout -schema wordlist.xsd
I get 我懂了
dictionary.xml:11: element word: Schemas validity error : Element 'word': This element is not expected.
dictionary.xml fails to validate
Line 11 is 第11行是
<word id="1">Triangle</word>
so it seems the first word works as expected, but not the second one... 所以第一个单词似乎按预期工作,但第二个单词却不起作用...
Change 更改
<xs:element name="word">
to 至
<xs:element name="word" maxOccurs="unbounded">
because the default for maxOccurs
is 1 , but you wish to allow multiple. 因为maxOccurs
的默认值为1 ,但是您希望允许多个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.