简体   繁体   English

如何使用w3c sitemap.xsd验证w3c网站地图和Google网站地图?

[英]How to use w3c sitemap.xsd to validate w3c sitemap & google sitemap?

w3c sitemap.xsd: http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd w3c sitemap.xsd: http : //www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd
It looks like this: 看起来像这样:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" targetNamespace="http://www.sitemaps.org/schemas/sitemap/0.9" elementFormDefault="qualified">

I have two sitemap file. 我有两个站点地图文件。
1. w3c sitmap file, like this: 1. w3c sitmap文件,如下所示:

<?xml version="1.0" encoding="UTF-8"?>                                                                                                                                                                                                       
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url><loc>http://t.qq.com/p/t/42509089158929/</loc></url>
</urlset>

2.google-sitemap file, like this: 2.google-sitemap文件,如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.google.com/schemas/sitemap/0.9"> 
<url>
<loc>http://blog.ifeng.com/article/11487489.html</loc>
<lastmod>2011-05-23T09:33:01+08:00</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
</urlset>

I use w3c sitemap.xsd to validate these two files by xmllint. 我使用w3c sitemap.xsd通过xmllint验证了这两个文件。
1. w3c stitemap file, normal and success 1. w3c stitemap文件,正常且成功
2. google-sitemap file, output like below 2. google-sitemap文件,输出如下

$ xmllint --schema sitemap.xsd sitemap_google.xml  --noout 
sitemap_google.xml:2: element urlset: Schemas validity error : Element '{http://www.google.com/schemas/sitemap/0.9}urlset': No matching global declaration available for the validation root.
sitemap_google.xml fails to validate

I think, the problem is the namespace is different in google-sitemap.xml and sitemap.xsd. 我认为,问题在于google-sitemap.xml和sitemap.xsd中的命名空间不同。 How should I do to use sitemap.xsd to validate these two sitemap file? 如何使用sitemap.xsd验证这两个Sitemap文件?

Thanks! 谢谢!

If there is no reference to the sitemaps.org sitemap schema in the google sitemap instance document then I don't see how you are supposed to validate it or even why you would want to. 如果Google站点地图实例文档中没有对sitemaps.org站点地图架构的引用,那么我看不到您应该如何验证它,甚至看不到为什么要这么做。

By including the namespace at the top of the file, the google sitemap instance is clearly stating that it is an instance of the google.com sitemap schema and not the sitemaps.org sitemap schema. 通过在文件顶部包含名称空间,Google Sitemap实例可以清楚地表明它是google.com Sitemap架构的实例,而不是sitemaps.org Sitemap架构的实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM