我目前正在使用一些基本的XS架構東西,但在嘗試驗證我的架構時出現惱人的錯誤。我使用XMLValidation.com,我得到的錯誤是:XML驗證問題:錯誤s4s-elt-must-match
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>
任何人有任何想法,爲什麼我的代碼不驗證,我可以做什麼來整理。在此先感謝
Thanks mate。這是訣竅! – Bic1245