我有以下XML代码段和相应的XML Schema:
<authors>
<author>
<keyname>Foo</keyname>
<forenames>Bar</forenames>
</author>
</authors>
架构:
<element name="authors" minOccurs="0" maxOccurs="1" type="arXiv:authorsType"/>
<complexType name="authorsType">
<sequence>
<element name="author" minOccurs="1" maxOccurs="unbounded" type="arXiv:authorType"/>
</sequence>
</complexType>
<complexType name="authorType">
<sequence>
<element name="keyname" minOccurs="1" maxOccurs="1" type="string"/>
<element name="forenames" minOccurs="0" maxOccurs="1" type="string"/>
<element name="suffix" minOccurs="0" maxOccurs="1" type="string"/>
<element name="affiliation" minOccurs="0" maxOccurs="unbounded" type="string"/>
</sequence>
</complexType>
但我很好奇架构如何允许这样:
<authors>
Text.
<author>
<keyname>Foo</keyname>
<forenames>Bar</forenames>
</author>
</authors>
答案 0 :(得分:1)
包含元素和文本节点的节点是 mixed content 的节点。您可以使用mixed
中的complexType
属性声明:
<complexType name="authorsType" mixed="true">
<sequence>
<element name="author" minOccurs="1" maxOccurs="unbounded" type="arXiv:authorType"/>
</sequence>
</complexType>
现在authorsType
接受包含字符内容的元素和文本节点。