html - XML 验证问题架构
问题描述
我对 XML 很陌生,我面临验证问题,如果我的 XML 和 XSD 文件结构良好,我也希望得到一些反馈。
在针对 XSD 验证 XML 时,我经常遇到错误 -> 元素类型“xs:schema”必须由匹配的结束标记“”终止
下面的 XML
<?xml version="1.0" encoding="UTF-8"?>
<alumnos xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="alumnos.xsd">
<alumno id=001>
<nombre>Samuel</nombre>
<apellido>Van Bladel</apellido>
<email>Samuelvanbladel@gmail.com</email>
<foto>https://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 id=002>
<nombre>Deniz</nombre>
<apellido>Turki</apellido>
<email>DenizTurki@gmail.com</email>
<foto>https://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 id=003>
<nombre>Denisa</nombre>
<apellido>Hermann</apellido>
<email>Denisahermann@gmail.com</email>
<foto>https://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 id=004>
<nombre>Bruno</nombre>
<apellido>porto</apellido>
<email>BrunoPorto@gmail.com</email>
<foto>https://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/2001XMLSchema-instance"
>
<!-- definition of simple elements -->
<xs:element name="nombre">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="0"/>
<xs:maxLength value="20"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="apellido">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="0"/>
<xs:maxLength value="30"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="comentario">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="0"/>
<xs:maxLength value="50"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="modulo">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="0"/>
<xs:maxLength value="10"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="nota" type="xs:string" >
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minLength value="0"/>
<xs:maxLength value="10"/>
</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 name="modulo">
<xs:complexType>
<xs:sequence>
<xs:element ref="nota"/>
<xs:element ref="comentario"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:element>
</xs:schema>
如果您发现其中任何一个错误,请随时指出。它们都有从模式到最大长度的限制。
谢谢!!!!
解决方案
您已在 XSD 中自行关闭了以下标签。
<xs:element name="email"/>
那是导致错误的原因。正确的方法是<xs:element name="email">
推荐阅读
- php - 在 Laravel 中使用视图作曲家时出现“MongoDB\Driver\Manager Not Found”
- python - 使用 NLTK 的 SklearnClassifier 和 ClassifierBasedPOSTagger 构建自己的基于分类器的词性标注器
- php - 从 html 文档中的合格 span 标签获取类值和文本
- flutter - Fluter 循环倒数计时器
- ios - 在swift函数中传递多个闭包并执行过滤
- python - 如何以编程方式查找已安装包的详细信息(pip 显示等效项)?
- postgresql - 只读列 pgadmin4:无法复制结果
- linux - GCP中的ufw防火墙
- git - git ls-tree 可以列出索引吗?
- istio - istio 与 docker 桌面集成