XML 验证问题:错误 s4s-elt-must-match [英] XML Validation issue: error s4s-elt-must-match

查看:49
本文介绍了XML 验证问题:错误 s4s-elt-must-match的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试一些基本的 XS 架构内容,但在尝试验证我的架构时遇到了令人恼火的错误.我正在使用 XMLValidation.com,我得到的错误是:

I'm currently playing around with some basic XS Schema stuff, but am getting an irritating error when attempting to validate my schema. I'm using XMLValidation.com and the error I'm getting is:

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如下:

Then, my XSD is as follows:

<?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 文件如下:

The corresponding XML file reads like:

<?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>

任何人都知道为什么我的代码没有通过验证以及我可以做些什么来解决它.提前致谢

Anyone have any ideas why my code isn't validating and what I can do to sort it out. Thanks in advance

推荐答案

我得到了以下工作...

I got the following to work...

<?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 验证问题:错误 s4s-elt-must-match的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆