我目前正在尝试一些基本的 XS 架构内容,但在尝试验证我的架构时遇到了令人恼火的错误。我正在使用 XMLValidation.com,收到的错误是:
s4s-elt-must-match.1: The content of 'lecturers' must match (annotation?, (simpleType | complexType)?, (unique | key | keyref)*)). A problem was found starting at: element.
然后,我的XSD如下:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="lecturers">
<xs:element name="lecturer">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:attribute name="title" type="xs:string" />
<xs:attribute name="first" type="xs:string" />
<xs:attribute name="last" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:element name="teaching">
<xs:complexType>
<xs:sequence>
<xs:element name="course" type="xs:string" />
<xs:attribute name="code" type="xs:string" />
<xs:element name="course" type="xs:string" />
<xs:attribute name="code" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="research" type="xs:string"/>
</xs:element>
</xs:element>
</xs:schema>
相应的 XML 文件如下所示:
<?xml version="1.0"?>
<lecturers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="lecturers.xsd">
<lecturer>
<name title="Professor" first="Peter" last="Quirk" />
<teaching>
<course code="CO3070">XML and the Web</course>
<course code="CO3300">Web Server Architectures</course>
</teaching>
<research>The application of Web protocols to Biology</research>
</lecturer>
</lecturers>
任何人都知道为什么我的代码无法验证以及我可以采取什么措施来解决它。提前致谢
最佳答案
我需要执行以下操作...
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="lecturers">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element name="lecturer">
<xs:complexType>
<xs:sequence>
<xs:element name="name">
<xs:complexType>
<xs:attribute name="title" type="xs:string" />
<xs:attribute name="first" type="xs:string" />
<xs:attribute name="last" type="xs:string" />
</xs:complexType>
</xs:element> <!-- name -->
<xs:element name="teaching">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element name="course">
<xs:complexType mixed="true">
<xs:attribute name="code" type="xs:string" />
</xs:complexType>
</xs:element> <!-- course -->
</xs:sequence>
</xs:complexType>
</xs:element> <!-- teaching -->
<xs:element name="research" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element> <!-- lecturer -->
</xs:sequence>
</xs:complexType>
</xs:element> <!-- lecturers -->
</xs:schema>
关于XML 验证问题 : error s4s-elt-must-match,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13670153/