错误:XML 验证器说尾随部分不允许内容和其他名称空间问题?

Errors: XML validator says conetent not allowed in trailing section and other namespace issues?

我这辈子都无法弄清楚是什么导致了我的 XML 文件和架构中的错误。它应该只是一个学校的高级模式,但是过了截止日期几天,尽管重新阅读了这一章,我还是想不通。这是我收到的错误:

It was detected that 'sm:sites' is in namespace 'http://www.sitemaps.org/schemas/sitemap/0.9/ns', but components from this namespace are not referenceable from schema document 'file. If this is the incorrect namespace, perhaps the prefix of 'sm:sites' needs to be changed. If this is the correct namespace, then an appropriate 'import' tag should be added 1 Error

Col 9 - Content is not allowed in trailing section. 1 Error

这是架构,XML:

<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="sm:sites" />
                  </xs:sequence>
               </xs:complexType>
            </xs:element>
         </xs:sequence>
      </xs:complexType>
   </xs:element>
</xs:schema>​
<sites xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="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>​​

非常感谢任何帮助,谢谢。

Col 9 - Content is not allowed in trailing section. 1 Error

当您看到这样的错误时,请尝试将每个文档解析为 XML。在这种情况下,在您的架构上使用 xmlparse

b:25: parser error : Extra content at the end of the document
</xs:schema>​
            ^

在二进制编辑器中查看该文件的末尾:

0000000 003c 002f 0078 0073 003a 0073 0063 0068
0000020 0065 006d 0061 003e 200b

U+003E就是>。然后,您的文档末尾有一个 U+200B(零宽度 space)。您的编辑器可能不会显示它,但它无效 XML。

在您的架构中,只需更改:

<xs:element ref="sm:sites" />

<xs:element ref="sm:urlset" />

这将引用您要重复使用的适当元素(即 urlset)- 否则这意味着您要再次插入 <sites> 元素。

然后在你的XML中,你需要改变:

<urlset xmlns:sm="http://www.sitemaps.org/schemas/sitemap/0.9/ns">

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9/ns">

它应该可以正常工作。这是必需的,因为您在架构中导入的 urlset 元素绑定到 http://www.sitemaps.org/schemas/sitemap/0.9/ns 命名空间。在前面的声明中,您将前缀 sm: 绑定到 url,但它不会更改您正在编写的元素的命名空间。