首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >找不到XML / XSD元素的声明

找不到XML / XSD元素的声明
EN

Stack Overflow用户
提问于 2020-03-13 10:07:12
回答 1查看 2.6K关注 0票数 0

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

在针对XSD -> No声明验证XSD:时,我经常会遇到错误。

我正在使用windows上的程序XML复制编辑器。我还尝试了一个针对XSD的在线验证器XML,并得到了这个错误。https://www.freeformatter.com/xml-validator-xsd.html

我得到错误Src-解析:无法将名称'string‘解析为A(n)’类型定义‘组件.

XML

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

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

回答 1

Stack Overflow用户

发布于 2020-03-13 15:28:32

错误“没有为元素xs:schema找到声明”。意味着您正在尝试验证架构,而不是实例文档。您还没有说明如何调用验证,但我怀疑在您使用的任何API中,您都错误地获得了模式和源文档。

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

https://stackoverflow.com/questions/60668458

复制
相关文章

相似问题

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