我有一个包含 sitemap.xml 文件的网站。目前,我的 sitemap.xml 文件如下所示:
<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://www.mysite.com/about/blog/post-1</loc>
<lastmod>2013-08-13</lastmod>
<changefreq>never</changefreq>
<blog:title>This is the title of the blog post</blog:title>
<blog:description>This is the description of the blog post</blog:description>
<blog:author>Some person</blog:author>
<blog:authorUrl>https://www.mysite.com/people/some-person</blog:authorUrl>
</url>
</urlset>
Run Code Online (Sandbox Code Playgroud)
正如上面的代码片段所示,我正在尝试扩展我的站点地图。我正在使用 sitemaps.org 中扩展站点地图协议部分中详细介绍的方法。
我创建了一个名为 blog.xsd 的 .xsd 文件。该文件位于http://www.mysite.com/data/blog.xsd。该文件如下所示:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="title">
<xs:restriction base="xs:string" />
</xs:simpleType>
<xs:simpleType name="description">
<xs:restriction base="xs:string" />
</xs:simpleType>
<xs:simpleType name="author">
<xs:restriction base="xs:string" />
</xs:simpleType>
<xs:simpleType name="authorUrl">
<xs:restriction base="xs:string" />
</xs:simpleType>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)
我试图弄清楚如何在我的站点地图文件中引用 blog.xsd 。目前,Google 网站管理员工具会用警告标记我的 sitemap.xml。我的警告是:“无法识别此标签。请修复它并重新提交。”。该警告涉及标题、描述、作者和authorUrl 标签。我怀疑这是因为我的 sitemap.xml 文件没有引用 blog.xsd。但是,我不知道该怎么做。有人可以举个例子吗?sitemaps.org 上的文档不是很清楚。谢谢你!
我的建议是阅读一般的 XML 和名称空间;它将帮助您更好地理解此类主题。
正如您在站点地图文档中看到的,您可以使用自己的元素在自己的命名空间中扩展站点地图。您的 xml 中缺少一个关键部分:尽管您blog:在元素上使用了名称空间前缀,但您从未声明名称空间前缀blog。
在站点地图文档中您会看到:
<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"
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:example="http://www.example.com/schemas/example_schema"> <!-- namespace extension -->
Run Code Online (Sandbox Code Playgroud)
这是最后一部分,xmlns:example="http://www.example.com/schemas/example_schema"这是至关重要的。
您需要为您的博客前缀提供一个命名空间 uri。它只需看起来像一个 URL,实际上并不需要存在。让我们使用http://www.mysite.com/data/blog/1.0- 您也可以使用其他任何东西。
那么你的站点地图就变成了:
<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:blog="http://www.mysite.com/data/blog/1.0">
<url>
<loc>http://www.mysite.com/about/blog/post-1</loc>
<lastmod>2013-08-13</lastmod>
<changefreq>never</changefreq>
<blog:title>This is the title of the blog post</blog:title>
<blog:description>This is the description of the blog post</blog:description>
<blog:author>Some person</blog:author>
<blog:authorUrl>https://www.mysite.com/people/some-person</blog:authorUrl>
</url>
</urlset>
Run Code Online (Sandbox Code Playgroud)
根据站点地图文档,这应该足够了。
如果您还希望能够使用 XML 架构验证器验证站点地图 XML,则可以将其更改<urlset为:
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:blog="http://www.mysite.com/data/blog/1.0"
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.mysite.com/data/blog/1.0
http://www.mysite.com/data/blog.xsd">
Run Code Online (Sandbox Code Playgroud)