首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >XML验证问题模式

XML验证问题模式
EN

Stack Overflow用户
提问于 2020-03-13 06:19:45
回答 1查看 62关注 0票数 1

我对XML非常陌生,我面临验证方面的问题,如果我的XML和XSD文件结构良好,我也希望得到一些反馈。

在对XSD ->验证XML时,我经常会收到错误元素类型"xs:schema“必须通过匹配的结束标记"”终止。

下面是XML

代码语言:javascript
运行
复制
<?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

代码语言:javascript
运行
复制
<?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>

如果你看到任何一个错误,你可以自由地指出。它们都有从模式到最大长度的限制。

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-13 07:03:59

您已经在XSD中关闭了下面的标签。

导致错误的<xs:element name="email"/>。正确的方式是<xs:element name="email">

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60665716

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档