错误:检测到“站点"没有命名空间,但架构文档无法引用没有目标命名空间的组件 [英] Error: It was detected that 'sites' has no namespace, but components with no target namespace are not referenceable from schema document

查看:30
本文介绍了错误:检测到“站点"没有命名空间,但架构文档无法引用没有目标命名空间的组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在流感期间一直在研究这个高级"模式,但我不明白为什么它一直告诉我找不到网站".我重新阅读了这一章,甚至创建了一个副本进行试验(以前有效),但我不明白.我正在尝试导入和组合模式,但我不确定如何使其正常工作......以下是错误:

I have been working on this "advanced" schema for days with the flu and I cannot figure out why it keeps telling me that "sites" is not found. I re-read the chapter and even created a copy to experiment with (which worked before) and I do not understand. I am trying to import and combine schemas and I am not sure how to get it to work properly... Here are the errors:

Ln 16 Col 84 - cvc-elt.1:找不到元素的声明站点".1 错误 [Xerces-J 2.9.1] 验证 XML 模式sites.xsd"... Ln 32 Col 49 - src-resolve.4.1:解析组件站点"时出错.检测到 'sites' 没有命名空间,但组件没有目标命名空间不可从架构文档中引用.

Ln 16 Col 84 - cvc-elt.1: Cannot find the declaration of element 'sites'. 1 Errors [Xerces-J 2.9.1] Validating XML Schema "sites.xsd" ... Ln 32 Col 49 - src-resolve.4.1: Error resolving component 'sites'. It was detected that 'sites' has no namespace, but components with no target namespace are not referenceable from schema document.

如果 'sites' 打算有一个命名空间,也许前缀需要提供.如果 'sites' 没有命名空间,那么应该添加没有命名空间"属性的导入"

If 'sites' is intended to have a namespace, perhaps a prefix needs to be provided. If it is intended that 'sites' has no namespace, then an 'import' without a "namespace" attribute should be added

这是架构:

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:cc="http://example.com/weekendfunsnacks/sites/ns"
      targetNamespace="http://example.com/weekendfunsnacks/sites"
      xmlns:sm="http://www.sitemaps.org/schemas/sitemap/0.9/ns"
            elementFormDefault="qualified" attributeFormDefault="unqualified">

 <xs:import namespace="http://www.sitemaps.org/schemas/sitemap/0.9"
             schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" />

   <xs:element name="sites">
      <xs:complexType>
         <xs:sequence>
            <xs:element name="site" maxOccurs="unbounded" minOccurs="0">
               <xs:complexType>
                  <xs:sequence>
                     <xs:element type="xs:string" name="name"/>
                     <xs:element type="xs:byte" name="totalPages" />
                     <xs:element ref="sites"  />
                  </xs:sequence>
               </xs:complexType>
            </xs:element>
         </xs:sequence>
      </xs:complexType>
   </xs:element>
</xs:schema>​

这里是 XML:

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<sites xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xs="http://example.com/weekendfunsnacks/sites/ns"
       xsi:schemaLocation="http://example.com/weekendfunsnacks/sites/ns sites.xsd">
    <site>
        <name>Weekend Fun Snacks</name>
        <totalPages>127</totalPages>
    <urlset xmlns:sm="http://www.sitemaps.org/schemas/sitemap/0.9/ns">
         <url>
            <loc>http://example.com/weekendfunsnacks/?cat=58</loc>
         </url>
         <url>
            <loc>http://example.com/weekendfunsnacks/?cat=2</loc>
            <lastmod>2017-12-29T06:03:34+00:00</lastmod>
         </url>
         <url>
            <loc>http://example.com/weekendfunsnacks/?cat=15</loc>
            <lastmod>2017-12-29T05:24:04+00:00</lastmod>
         </url>
         <url>
            <loc>http://example.com/weekendfunsnacks/?cat=93</loc>
         </url>
         <url>
            <loc>http://example.com/weekendfunsnacks/?cat=55</loc>
         </url>
      </urlset>
    </site>
    <site>
        <name>Paleo Snacks</name>
        <totalPages>52</totalPages>
    <urlset xmlns:sm="http://www.sitemaps.org/schemas/sitemap/0.9/ns">
         <url>
            <loc>http://example.com/primalsnacks/?cat=6</loc>
         </url>
         <url>
            <loc>http://example.com/primalsnacks/?cat=18</loc>
            <lastmod>2017-09-19T17:13:19+00:00</lastmod>
         </url>
         <url>
            <loc>http://example.com/primalsnacks/?cat=54</loc>
            <lastmod>2017-09-19T15:24:01+00:00</lastmod>
         </url>
         <url>
            <loc>http://example.com/primalsnacks/?cat=52</loc>
            <lastmod>2017-09-28T21:03:11+00:00</lastmod>
         </url>
         <url>
            <loc>http://example.com/primalsnacks/?cat=201</loc>
            <lastmod>2017-10-06T07:03:26+00:00</lastmod>
         </url>
         <url>
            <loc>http://example.com/primalsnacks/?cat=11</loc>
         </url>
      </urlset>
    </site>
    <site>
        <name>Veg Snacks</name>
        <totalPages>17</totalPages>
     <urlset xmlns:sm="http://www.sitemaps.org/schemas/sitemap/0.9/ns">
         <url>
            <loc>http://example.com/vegsnacks/?cat=102</loc>
         </url>
         <url>
            <loc>http://example.com/vegsnacks/?cat=23</loc>
         </url>
         <url>
            <loc>http://example.com/vegsnacks/?cat=1</loc>
         </url>
         <url>
            <loc>http://example.com/vegsnacks/?cat=55</loc>
            <lastmod>2017-06-12T08:05:32+00:00</lastmod>
         </url>
         <url>
            <loc>http://example.com/vegsnacks/?cat=201</loc>
         </url>
         <url>
            <loc>http://example.com/vegsnacks/?cat=87</loc>
         </url>
      </urlset>
    </site>
</sites>​

推荐答案

你的 XSD 有一个 targetNamespace,所以你的 ref="sites" 必须引用那个命名空间.

Your XSD has a targetNamespace, so your ref="sites" has to reference that namespace.

定义一个命名空间前缀,比如w:,与目标命名空间相同,然后在引用中使用:ref=w:sites":

Define a namespace prefix, say w:, to be the same as the target namespace, and then use it in the reference: ref="w:sites":

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
             targetNamespace="http://example.com/weekendfunsnacks/sites"
             xmlns:w="http://example.com/weekendfunsnacks/sites"
             elementFormDefault="qualified" attributeFormDefault="unqualified">
    
  <xs:import namespace="http://www.sitemaps.org/schemas/sitemap/0.9"
             schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" />
  
  <xs:element name="sites">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="site" maxOccurs="unbounded" minOccurs="0">
          <xs:complexType>
            <xs:sequence>
              <xs:element type="xs:string" name="name"/>
              <xs:element type="xs:byte" name="totalPages" />
              <xs:element ref="w:sites"  />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>
  
  

这篇关于错误:检测到“站点"没有命名空间,但架构文档无法引用没有目标命名空间的组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆