XSD error: The content is not valid. Expected is (annotation?)

XSD error: The content is not valid. Expected is (annotation?)

我正在尝试写一篇 XSD。当我尝试使用此 XSD 解析 XML 时,以下组件导致错误。错误信息是

The content is not valid. Expected is (annotation?)., Line 9

我尝试删除 xs:annotation 部分,但没有成功。我在别处定义了 'Job' 和 'JobParameter'。有人可以帮我吗?

<xs:complexType name='JobsType'>
    <xs:annotation>
      <xs:documentation>
        A collection of Jobs for this component
      </xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element ref='Job' minOccurs='1' maxOccurs='unbounded'>
        <xs:complexType>
          <xs:annotation>
            <xs:documentation>
              A job element
            </xs:documentation>
          </xs:annotation>
          <xs:sequence>
            <xs:element name='JobParameters' type='JobParametersType' minOccurs='0' maxOccurs='1'>
              <xs:annotation>
                <xs:documentation>
                  A collection of job parameters
                </xs:documentation>
              </xs:annotation>
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name='JobParametersType'>
    <xs:annotation>
      <xs:documentation>
        A collection of Actions for this component
      </xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element ref='JobParameter' minOccurs='1' maxOccurs='unbounded'/>
    </xs:sequence>
  </xs:complexType>

使用xs:element/@ref引用全局声明的元素。

使用 xs:element/@name 为您在此处本地声明的元素指定名称。

使用 @ref@name您不能同时使用两者

以下是对您的 XSD 应用的上述更正。请注意,JobParameter 元素可能会在其他地方定义一个可以引用的定义,但由于您没有包含它,我继续将它也更改为 @name 属性。你可能想要改变它。

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           elementFormDefault="qualified">

  <xs:complexType name='JobsType'>
    <xs:annotation>
      <xs:documentation>
        A collection of Jobs for this component
      </xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element name='Job' minOccurs='1' maxOccurs='unbounded'>
        <xs:complexType>
          <xs:annotation>
            <xs:documentation>
              A job element
            </xs:documentation>
          </xs:annotation>
          <xs:sequence>
            <xs:element name='JobParameters' 
                        type='JobParametersType' minOccurs='0' maxOccurs='1'>
              <xs:annotation>
                <xs:documentation>
                  A collection of job parameters
                </xs:documentation>
              </xs:annotation>
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name='JobParametersType'>
    <xs:annotation>
      <xs:documentation>
        A collection of Actions for this component
      </xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element name='JobParameter' 
                  minOccurs='1' maxOccurs='unbounded'/>
    </xs:sequence>
  </xs:complexType>

</xs:schema>