首页 > 解决方案 > 根架构没有匹配的全局声明的验证错误

问题描述

我知道有很多这些错误的实例,但这些类型的验证错误对我来说没有多大意义

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:element name="Artwork">
     <xs:complexType>
      <xs:sequence>

        <xs:element name="title" type="xs:string"/>
        <xs:element name="media" type="xs:string"/>
        <xs:element name="description" type="xs:string"/>
        <xs:element name="created" type="xs:string"/>
        <xs:element name="display" type="xs:string"/>
      </xs:sequence>
    </xs:complexType>
    </xs:element>
 </xs:schema>

我尝试切换模式名称,但没有做任何事情。我还需要显示 XML 文件来解决这个问题吗?我在那里拥有的唯一代码是将其链接到相同模式的代码命名空间对我来说似乎很好..这是XML





`
<Schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="artwork.xsd">

<Artworks>
 <Artwork>
     <Title>Xtreme Air</Title>
     <Media>Glass Sculpture</Media>
     <Description>An amazing work that uses glass balloon shaps to illustrate a rainbow of balloons circuling a glass earth.</Description>
     <Created>April 2010</Created>
     <Display>Orlando Museum of Arts</Display>
  </Artwork>
</Artworks>
</Schema>
`

标签: xmlxsd-validation

解决方案


请尝试以下 XML/XSD 对。您需要xsi:noNamespaceSchemaLocation使用环境中的 XSD 文件位置更新该值。

XML

<?xml version="1.0"?>
<Artworks xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file:///e:/Temp/Artwork.xsd">
    <Artwork>
        <Title>Xtreme Air</Title>
        <Media>Glass Sculpture</Media>
        <Description>An amazing work that uses glass balloon shaps to illustrate a rainbow of balloons circuling a glass earth.</Description>
        <Created>April 2010</Created>
        <Display>Orlando Museum of Arts</Display>
    </Artwork>
</Artworks>

XSD

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xs:element name="Artworks">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="Artwork"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="Artwork">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="Title" type="xs:string"/>
                <xs:element name="Media" type="xs:string"/>
                <xs:element name="Description" type="xs:string"/>
                <xs:element name="Created" type="xs:string"/>
                <xs:element name="Display" type="xs:string"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

推荐阅读