错误:检测到“站点”没有名称空间,但是没有目标名称空间的组件无法从架构文档中引用

宝808

流感已经有好几天了,我一直在研究这种“高级”模式,但我不知道为什么它总是告诉我找不到“站点”。我重新阅读了本章,甚至创建了一个副本来进行试验(以前工作过),但我不理解。我正在尝试导入和合并架构,但不确定如何使其正常工作...以下是错误:

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

如果“站点”打算具有名称空间,则可能需要提供前缀。如果希望“站点”没有名称空间,则应添加不具有“名称空间”属性的“导入”

这是模式:

<?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"必须引用该名称空间。

定义一个名称空间前缀,例如w:与目标名称空间相同,然后在引用中使用它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>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章