如何验证兼容的 XML 站点地图?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/305081/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 12:12:52  来源:igfitidea点击:

How to validate compliant XML sitemap?

xmlsitemap

提问by Jesse

For the following header I get the same two errors on all my sitemaps. It's confusing because, if Google can't read my sitemap, then how can they say that each URL has the same priority? The header counts as line 2, after the XML declaration. Google claims only to have indexed about 2% of the URLs from the maps. Please help.

对于以下标题,我在所有站点地图上都遇到了相同的两个错误。这很令人困惑,因为如果 Google 无法读取我的站点地图,那么他们怎么能说每个 URL 具有相同的优先级呢?标题算作第 2 行,在 XML 声明之后。谷歌声称只索引了地图中大约 2% 的 URL。请帮忙。

UPDATE: I think the problem is that I don't know how to validate against a schema. How to do that?

更新:我认为问题在于我不知道如何针对架构进行验证。怎么做?

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">

==Parsing error
We were unable to read your Sitemap. It may contain an entry we are 
unable to recognize. Please validate your Sitemap before resubmitting.

==Notice
All the URLs in your Sitemap have the same priority...

UPDATE: Please be patient, first time validating XML. I don't understand the errors.

更新:请耐心等待,第一次验证 XML。我不明白这些错误。

Errors in the XML document:
    4:  80  SchemaLocation: schemaLocation value = 'http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd' must have even number of URI's.
    4:  80  cvc-elt.1: Cannot find the declaration of element 'urlset'.

XML document:
1   <?xml version="1.0" encoding="UTF-8"?>
2   <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4     xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
5     <url>
6       <loc>http://nutrograph.com/1-butter-salted</loc>
7       <changefreq>monthly</changefreq>
8       <priority>0.8</priority>
9     </url>
10    <url>
11      <loc>http://nutrograph.com/2-butter-whipped-with-salt</loc>
12      <changefreq>monthly</changefreq>
13      <priority>0.8</priority>
14    </url>
15  </urlset>

采纳答案by TToni

Have you validated your XML against the schema given here: http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd

您是否根据此处给出的架构验证了您的 XML:http: //www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd

If yes, what was the result?

如果有,结果如何?

If not, what is the URL of your sitemap?

如果没有,您的站点地图的 URL 是什么?

If you don't know how to validate the XML against the schema, use http://www.xmlvalidation.com/

如果您不知道如何根据架构验证 XML,请使用http://www.xmlvalidation.com/

Paste the sitemap-XML there, click on "Validate against external XML schema" and paste the schema after clicking the Validate-button.

将站点地图 XML 粘贴到那里,单击“针对外部 XML 架构进行验证”,然后在单击验证按钮后粘贴架构。

This will tell you what's wrong with your XML. If you don't know how to interpret the result, please amend your original question accordingly.

这将告诉您 XML 有什么问题。如果您不知道如何解释结果,请相应地修改您的原始问题。

Edit: The error was a missing namesapce-URL in the schemaLocation. The first tag has to look like this:

编辑:错误是 schemaLocation 中缺少名称空间 URL。第一个标签必须如下所示:

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
 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">

回答by Mike Edwards

Strike the above. Looking at Googles site, their sitemap header seems to be a little longer than yours.

打击以上。看看谷歌的网站,他们的站点地图标题似乎比你的要长一点。

It's on this page: https://www.google.com/webmasters/tools/docs/en/protocol.html

它在这个页面上:https: //www.google.com/webmasters/tools/docs/en/protocol.html

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
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">

回答by Mike Edwards

Nottice that the schemaLocation has 2 URi's... (must have even number of URI's)

请注意,schemaLocation 有 2 个 URI...(必须有偶数个 URI)

It should look like this: **

它应该是这样的:**

xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"

xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"

**

**

回答by Herry

I was also missing something in this syntax

我在这个语法中也遗漏了一些东西

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xs">

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xs">

Do you what was missing this syntax?!

你是不是缺少这个语法?!

Just Letter "d" at the end of url extensions (http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xs)

在 url 扩展 ( http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xs)结尾处只用字母“d”

Resolve my this issue after adding letter "d"

添加字母“d”后解决我的这个问题