使用 url 元素内的 xhtml:link 验证 XML 站点地图 urlset

Sta*_*ser 6 xml sitemap xhtml xsd xml-namespaces

我正在尝试创建如下所示的站点地图,但出现此错误:

 <?xml version="1.0" encoding="UTF-8"?>
  <urlset
    xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" 
    xmlns:xhtml="http://www.w3.org/1999/xhtml" 
    xhtml:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
        http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
     <url>
         <loc>http://www.something.com/something</loc>
         <xhtml:link rel="alternate" hreflang="en-us" href="http://www.something.com/something" />
     </url>
 </urlset>
Run Code Online (Sandbox Code Playgroud)

错误:

http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd ">^ 错误 1866:元素 '{ http://www.sitemaps.org/schemas/sitemap/0.9 }urlset',属性 '{ http://www.w3.org/1999/xhtml }schemaLocation':不允许使用属性 '{ http://www.w3.org/1999/xhtml }schemaLocation'。在线:3

'{ http://www.w3.org/1999/xhtml }link':没有匹配的全局元素声明可用,但严格通配符要求。

请指教。谢谢你。

Ghi*_*rny 7

这个文档有两个问题:

  1. schemaLocation 属性必须在 XML 架构实例命名空间中。

  2. url 元素无效,因为它的定义说明processContents="strict"了 XHTML 的模式丢失,因此在范围内没有 xhtml:link 声明。

    <?xml version="1.0" encoding="UTF-8"?>
    <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:xhtml="http://www.w3.org/1999/xhtml"
        xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
        http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd
        http://www.w3.org/1999/xhtml
        http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd">
      <url>
        <loc>http://www.something.com/something</loc>
        <xhtml:link rel="alternate" hreflang="en-us" href="http://www.something.com/something" />
      </url>
    </urlset>
    
    Run Code Online (Sandbox Code Playgroud)

  • 难以置信,我需要进行多少次搜索才能找到这个支持验证的 `&lt;urlset&gt;` 组合和 `&lt;xhtml:link&gt;`。非常感谢 (3认同)
  • 我将所有完整的合格链接更新为 https,之后它就起作用了。 (2认同)

小智 7

旧的 - 但在搜索时仍然会出现。实际上问题是您正在使用 xhtml:link 然后您需要“其他”urlsets... http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd

<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd http://www.w3.org/TR/xhtml11/xhtml11_schema.html http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/TR/xhtml11/xhtml11_schema.html">
Run Code Online (Sandbox Code Playgroud)

参考: XML Sitemap 呈现为纯文本