带有Schema的XML没有验证并且给我“元素声明的内容必须匹配”

问题描述 投票:-1回答:1

我一直试图弄清楚为什么这个.xsd和.xml没有验证。我在第17行,第57栏上写了一个错误

“元素声明的内容必须匹配(注释?,(simpleType | complexType)?,(unique | key keyref)*)

奇怪的是,如果我删除.xsd和.xml中的第17行,由于某种原因,错误仍会在同一位置弹出。

这是我的XML代码:

<?xml version="1.0" encoding="UTF-8"?>
<cursos xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="reto4MarcasGrupo1Schema.xsd">
        <curso codigoCurso="AA2000">
          <nombreCurso>Manejo Ofimatica</nombreCurso>
          <numPlazas>20</numPlazas>
          <numHoras horario="diurno">300</numHoras>
          <fechaInicio>18-2-2018</fechaInicio>
          <fechaFin> 30-3-2018</fechaFin>
          <objetivos>Los objetivos de este curso es que las personas tengan un manejo basico de apliaciones de ofimatica</objetivos>
          <entidadColaboradora nombreEntidad="H"/>
          <diaSemana>L</diaSemana>
          <cuotas tipoCuotas="subvencionado100"/>
          <equipamiento>Ordeandores basicos</equipamiento>
          <dirigidoA tipoDirigido="desempleadosYempleados"/>
          <estado tipoEstado="aRealizar"/>
          <programa>
              <tema codigoTema="AAT001">
                <tituloTema>Introduccion</tituloTema>
                <impartidor>Ron Weasly</impartidor>
              </tema>
              <tema codigoTema="AAT002">
                <tituloTema>Introduccion</tituloTema>
                <impartidor>Jon Nieve</impartidor>
              </tema>
          </programa>
        </curso>
</cursos>

这是一个组织不同年级的课程的练习。

这是我的架构:

    <?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="cursos" type="tipoCursos"/>

  <xs:complexType name="tipoCursos">
    <xs:sequence>
      <xs:element name="curso" type="tipoCurso" minOccurs="1" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="tipoCurso">
    <xs:sequence>
      <xs:element name="nombreCurso" type="xs:string"/>
      <xs:element name="numPlazas" type="xs:nonNegativeInteger"/>
      <xs:element name="numHoras" type="tipoNumHoras"/>
      <xs:element name="fechaInicio" type="xs:date"/>
      <xs:element name="objetivos" type="xs:string"/>
      <xs:element name="entidadColaboradora" type="tipoEntidadColaboradora"/>
      <xs:element name="diaSemana" type="xs:string"/>
      <xs:element name="cuotas" type="cuotaTipo"/>
      <xs:element name="equipamiento" type="xs:string"/>
      <xs:element name="dirigidoA" type="tipoDirigido"/>
      <xs:element name="estado" type="estadoTipo"/>
      <xs:element name="programa" type="tipoPrograma"/>
    </xs:sequence>
    <xs:attribute name="codigoCurso" type="xs:ID"/>
  </xs:complexType>

  <xs:complexType name="tipoPrograma">
    <xs:sequence>
      <xs:element name="tema" type="tipoTema" minOccurs="1" maxOccurs="unbounded" />
  </xs:sequence>
  </xs:complexType>

  <xs:complexType name="tipoTema">
    <xs:sequence>
      <xs:element name="tituloTema" type="xs:string"/>
      <xs:element name="impartidor" type="xs:string"/>
    </xs:sequence>
    <xs:attribute name="codigoTema" type="xs:ID"/>
  </xs:complexType>

  <xs:complexType name="tipoNumHoras">
    <xs:sequence>
      <xs:element name="numHoras" type="xs:nonNegativeInteger"/>
    </xs:sequence>
    <xs:attribute name="horario" type="tipoHorario"/>
  </xs:complexType>

  <xs:simpleType name="cuotaTipo">
      <xs:restriction base="xs:string">
          <xs:enumeration value="subvencionado100"/>
          <xs:enumeration value="subvencionParcial"/>
          <xs:enumeration value="sinSubvencion"/>
      </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="estadoTipo">
      <xs:restriction base="xs:string">
          <xs:enumeration value="aplazado"/>
          <xs:enumeration value="realizado"/>
          <xs:enumeration value="aRealizar"/>
      </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="tipoDirigido">
      <xs:restriction base="xs:string">
          <xs:enumeration value="desempleadosYempleados"/>
          <xs:enumeration value="preferiblementeEmpleados"/>
          <xs:enumeration value="segunCursos"/>
      </xs:restriction>
  </xs:simpleType>


  <xs:simpleType name="tipoEntidadColaboradora">
      <xs:restriction base="xs:string">
          <xs:enumeration value="H"/>
          <xs:enumeration value="HC"/>
          <xs:enumeration value="S"/>
          <xs:enumeration value="I"/>
          <xs:enumeration value="D"/>
          <xs:enumeration value="E"/>
          <xs:enumeration value="J"/>
          <xs:enumeration value="M"/>
      </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="tipoHorario">
      <xs:restriction base="xs:string">
          <xs:enumeration value="diurno"/>
          <xs:enumeration value="nocturno"/>
      </xs:restriction>
  </xs:simpleType>

</xs:schema>
xml validation schema
1个回答
0
投票

错误消息表明架构无效。但我不认为它指的是你向我们展示的架构,因为那个很好。所以我认为你需要告诉我们更多关于你正在做什么的信息:例如你正在使用哪个模式处理器,以及你如何调用它。 (也许是xsi:schemaLocation属性中引用的模式是罪魁祸首?)

您的实例文档对架构无效。以下是Saxon报告的错误:

Validation error on line 6 column 50 of test.xml:
  FORG0001: The content model for element <numHoras> does not allow character content
  See http://www.w3.org/TR/xmlschema-1/#cvc-complex-type clause 2.3
Validation error on line 6 column 36 of test.xml:
  FORG0001: In content of element <numHoras>: Empty content is not allowed. Expected <numHoras>. 
  See http://www.w3.org/TR/xmlschema-1/#cvc-complex-type clause 2.4
Validation error on line 7 column 22 of test.xml:
  FORG0001: The content "18-2-2018" of element <fechaInicio> does not match the required
  simple type. Invalid date "18-2-2018" (Year is less than four digits)
  See http://www.w3.org/TR/xmlschema-2/#cvc-datatype-valid clause 1
Validation error on line 8 column 19 of test.xml:
  FORG0001: In content of element <curso>: The content model does not allow element
  <fechaFin> to appear immediately after element <fechaInicio>. Expected <objetivos>. 
  See http://www.w3.org/TR/xmlschema-1/#cvc-complex-type clause 2.4
Validation error on line 10 column 49 of test.xml:
  FORG0001: Attribute @nombreEntidad is not allowed on element <entidadColaboradora>
  See http://www.w3.org/TR/xmlschema-1/#cvc-complex-type clause 3
Validation error on line 10 column 49 of test.xml:
  FORG0001: The content "" of element <entidadColaboradora> does not match the required
  simple type. Value "" contravenes the enumeration facet "D, E, HC, M, H, I, J, S" of the
  type tipoEntidadColaboradora
  See http://www.w3.org/TR/xmlschema-2/#cvc-datatype-valid clause 1
Validation error on line 12 column 48 of test.xml:
  FORG0001: Attribute @tipoCuotas is not allowed on element <cuotas>
  See http://www.w3.org/TR/xmlschema-1/#cvc-complex-type clause 3
Validation error on line 12 column 48 of test.xml:
  FORG0001: The content "" of element <cuotas> does not match the required simple type.
  Value "" contravenes the enumeration facet "subvencionado100, subvencionPa..." of the type cuotaTipo
  See http://www.w3.org/TR/xmlschema-2/#cvc-datatype-valid clause 1
Validation error on line 14 column 59 of test.xml:
  FORG0001: Attribute @tipoDirigido is not allowed on element <dirigidoA>
  See http://www.w3.org/TR/xmlschema-1/#cvc-complex-type clause 3
Validation error on line 14 column 59 of test.xml:
  FORG0001: The content "" of element <dirigidoA> does not match the required simple type.
  Value "" contravenes the enumeration facet "preferiblementeEmpleados, segu..." of the type
  tipoDirigido
  See http://www.w3.org/TR/xmlschema-2/#cvc-datatype-valid clause 1
Validation error on line 15 column 41 of test.xml:
  FORG0001: Attribute @tipoEstado is not allowed on element <estado>
  See http://www.w3.org/TR/xmlschema-1/#cvc-complex-type clause 3
Validation error on line 15 column 41 of test.xml:
  FORG0001: The content "" of element <estado> does not match the required simple type.
  Value "" contravenes the enumeration facet "realizado, aRealizar, aplazado" of the type estadoTipo
  See http://www.w3.org/TR/xmlschema-2/#cvc-datatype-valid clause 1
Validation error on line 27 column 10 of test.xml:
  FORG0001: Twelve validation errors were reported
Validation of file test.xml completed: errors found

但这与您发布的错误无关。

© www.soinside.com 2019 - 2024. All rights reserved.