我对XML非常陌生,我面临验证方面的问题,如果我的XML和XSD文件结构良好,我也希望得到一些反馈。
在针对XSD -> No声明验证XSD:时,我经常会遇到错误。
我正在使用windows上的程序XML复制编辑器。我还尝试了一个针对XSD的在线验证器XML,并得到了这个错误。https://www.freeformatter.com/xml-validator-xsd.html
我得到错误Src-解析:无法将名称'string‘解析为A(n)’类型定义‘组件.
XML
<?xml version="1.0" encoding="UTF-8"?>
<alumnos>
<alumno>
<nombre>Samuel</nombre>
<apellido>Van Bladel</apellido>
<email>Samuelvanbladel@gmail.com</email>
<foto>google.com</foto>
<expediente>NX-0001R</expediente>
<curso>1</curso>
<modulo>Mark up languages
<nota>10/10</nota>
<comentario>Muy bien hecho hasta el techo.</comentario>
</modulo>
<modulo>Java
<nota>9/10</nota>
<comentario>Codigo muy bien structurada.</comentario>
</modulo>
</alumno>
<alumno>
<nombre>Deniz</nombre>
<apellido>Turki</apellido>
<email>DenizTurki@gmail.com</email>
<foto>google.com</foto>
<expediente>NX-0002R</expediente>
<curso>2</curso>
<modulo>Mark up languages
<nota>10/10</nota>
<comentario>Muy bien hecho hasta el techo.</comentario>
</modulo>
<modulo>Java
<nota>9/10</nota>
<comentario>Codigo muy bien structurada.</comentario>
</modulo>
</alumno>
<alumno>
<nombre>Denisa</nombre>
<apellido>Hermann</apellido>
<email>Denisahermann@gmail.com</email>
<foto>google.com</foto>
<expediente>NX-0003R</expediente>
<curso>3</curso>
<modulo>Mark up languages
<nota>10/10</nota>
<comentario>Muy bien hecho hasta el techo.</comentario>
</modulo>
<modulo>Java
<nota>9/10</nota>
<comentario>Codigo muy bien structurada.</comentario>
</modulo>
</alumno>
<alumno>
<nombre>Bruno</nombre>
<apellido>porto</apellido>
<email>BrunoPorto@gmail.com</email>
<foto>google.com</foto>
<expediente>NX-0004R</expediente>
<curso>4</curso>
<modulo>Mark up languages
<nota>10/10</nota>
<comentario>Muy bien hecho hasta el techo.</comentario>
</modulo>
<modulo>Java
<nota>9/10</nota>
<comentario>Codigo muy bien structurada.</comentario>
</modulo>
</alumno>
</alumnos>XSD
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- definition of simple elements -->
<xs:element name="nombre">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z0-9]{20}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="apellido">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z0-9]{30}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="comentario">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z0-9]{50}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="modulo">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z0-9]{10}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="nota" >
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:pattern value="[0-9]{8}"/>
</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="http://.+" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="expediente">
<xs:simpleType>
<xs:restriction base="string">
<xs:pattern value="NX + [0-9][0-9][0-9][0-9][0-9] + R"/>
</xs:restriction>
</xs:simpleType>
<!-- definition of attributes -->
<xs:attribute name="id" type="xs:integer" use="required"/>
<!-- definition of complex elements -->
<xs:element name="alumno">
<xs:complexType>
<xs:sequence>
<xs:element ref="nombre"/>
<xs:element ref="apellido"/>
<xs:element ref="modulo"/>
<xs:element ref="nota"/>
<xs:element ref="expediente"/>
<xs:element ref="foto"/>
<xs:element ref="email"/>
<xs:element ref="comentario"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:element>
</xs:schema>发布于 2020-03-13 15:28:32
错误“没有为元素xs:schema找到声明”。意味着您正在尝试验证架构,而不是实例文档。您还没有说明如何调用验证,但我怀疑在您使用的任何API中,您都错误地获得了模式和源文档。
https://stackoverflow.com/questions/60668458
复制相似问题