第 2 行错误:找不到元素"xs:schema"的声明



我很难根据XML文件验证XSD文件。

我的XML验证很好,但当试图对我的XSD文件执行同样的操作时,它不断返回以下错误:

第2行出现错误:未找到元素xs:schema的声明

我使用的是XML副本编辑器,但当我使用诸如https://www.freeformatter.com/xml-validator-xsd.html没有问题。我仍然想知道为什么我会得到这个错误,因为我看不到一种方法来声明"schema",它是根?或者我错了。两者都本地存储在我的电脑上。

下面是XML

<?xml version="1.0" encoding="UTF-8"?>
<students 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="schema.xsd">

<alumno id="001">
<nombre>Samuel</nombre>
<apellido>Van Bladel</apellido>
<email>Samuelvanbladel@gmail.com</email>
<foto>https://google.com</foto> 
<expediente>NX0001R</expediente>
<curso>1</curso> 

<modulo>
<modulonom>daw1</modulonom>
<nota>10</nota>
<comentario>Muy bien hecho hasta el techo</comentario>
</modulo>
<modulo> 
<modulonom>daw2</modulonom>
<nota>10</nota>
<comentario>Muy bien hecho hasta el techo</comentario>
</modulo>
</alumno>
<alumno id="002">
<nombre>Chris</nombre>
<apellido>den oudste</apellido>
<email>chris@gmail.com</email>
<foto>https://google.com</foto> 
<expediente>NX0002R</expediente>
<curso>1</curso> 

<modulo>
<modulonom>daw1</modulonom>
<nota>6</nota>
<comentario>muy bien</comentario>
</modulo>
<modulo> 
<modulonom>daw2</modulonom>
<nota>10</nota>
<comentario>Grande</comentario>
</modulo>
</alumno>
<alumno id="003">
<nombre>Denisa</nombre>
<apellido>Hermann</apellido>
<email>denisa@gmail.com</email>
<foto>https://google.com</foto> 
<expediente>NX0003R</expediente>
<curso>1</curso> 

<modulo>
<modulonom>daw3</modulonom>
<nota>9</nota>
<comentario>molt be</comentario>
</modulo>
<modulo> 
<modulonom>daw2</modulonom>
<nota>5</nota>
<comentario>lo puedes mejorar</comentario>
</modulo>
</alumno>

<alumno id="004">
<nombre>Deniz</nombre>
<apellido>Turkmenista</apellido>
<email>deniz@gmail.com</email>
<foto>https://google.com</foto> 
<expediente>NX0004R</expediente>
<curso>3</curso> 

<modulo>
<modulonom>daw6</modulonom>
<nota>9</nota>
<comentario>Crack</comentario>
</modulo>
<modulo> 
<modulonom>daw2</modulonom>
<nota>7</nota>
<comentario>Falta un</comentario>
</modulo>
</alumno>

</students>

低于的XSD

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

<xs:attribute name="id" type="xs:string"/>
<xs:element name="nombre">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="10"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="apellido">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="30"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="email"> 
<xs:simpleType > 
<xs:restriction base="xs:string"> 
<xs:pattern value="[^@]+@[^.]+..+"/> 
</xs:restriction> 
</xs:simpleType> 
</xs:element>
<xs:element name="foto">
<xs:simpleType>
<xs:restriction base="xs:anyURI">
<xs:pattern value="https://.+" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="expediente">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[A-Z][A-Z][0-9][0-9][0-9][0-9][A-Z]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="curso">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:pattern value="([0-9])*"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="modulonom">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="30"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="nota"  >
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="3"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="comentario">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50"/>
</xs:restriction>
</xs:simpleType>
</xs:element>

<xs:element name="students" >
<xs:complexType>
<xs:sequence>
<xs:element ref="alumno" maxOccurs="unbounded"/>                           
</xs:sequence>    
</xs:complexType>
</xs:element>

<xs:element name="alumno">
<xs:complexType>
<xs:sequence>
<xs:element ref="nombre"/>
<xs:element ref="apellido"/>
<xs:element ref="email"/>
<xs:element ref="foto"/>
<xs:element ref="expediente"/>
<xs:element ref="curso"/>     
<xs:element ref="modulo" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute ref="id" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="modulo">
<xs:complexType>
<xs:sequence>
<xs:element ref= "modulonom"  />     
<xs:element ref= "nota"  />
<xs:element ref= "comentario"  />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

我确实打开和关闭了我所能看到的一切,所以我不明白为什么会出现这个错误。

错误,

第2行出现错误:找不到元素"xs:schema"的声明

表明您错误地试图验证XSD本身,而不是验证XML实例文档。

如果您确实希望验证XSD,毕竟它也是一个XML文档,那么可以使用XMLSchemaforSchemas。但是,同样,您必须小心地向验证器指定哪个文档是要验证的XML,哪个文档是XSD。

最新更新