XML 验证问题 : error s4s-elt-must-match

标签 xml validation xsd schema

我目前正在尝试一些基本的 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/

相关文章:

forms - 针对多个约束验证表单字段

java - 通过自定义 Spring validator 处理绑定(bind)到输入字段的长值是否太晚了?

jaxb - 通过 wsimport 使用 JAXB 剧集文件

xml - 具有可选子元素的默认 XML 序列(或全部)是否必须至少有一个子元素?

java - org.xml.sax.SAXParseException; lineNumber : 6; columnNumber: 122; cvc-elt. 1:找不到元素 'beans' 的声明

javascript - NodeJS Express 嵌套输入主体对象验证

c# - XInclude 的替代品

xml - 使用 Perl XML::DOM 模块的解析器错误, "reference to invalid character number"

Python ElementTree - 在写得不好的 XML 中搜索子/孙

xml - POX ("plain old XML") 的意义是什么?