我目前正在玩一些基本的XS Schema,但在尝试验证我的架构时遇到了一个恼人的错误。我正在使用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>
任何人都有任何想法,为什么我的代码没有验证,我可以做些什么来解决它。提前致谢
答案 0 :(得分:1)
我有以下工作......
<?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>
答案 1 :(得分:1)
讲师必须像其他元素一样包含complexType: -
<xs:element name="lecturers">
<xs:complexType>
<xs:sequence>
<xs:element name="lecturer">
<xs:complexType>
<xs:sequence>
...
这个错误虽然含糊不清,却是这么说的。
答案 2 :(得分:0)
要验证xml,此架构将执行此操作。
<xs:element name="teaching">
<xs:complexType>
<xs:sequence>
<xs:element name="course" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="code" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="research" type="xs:string"/>