2012-07-02 37 views
0

W3C sitemap.xsd:http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd
它看起來像這樣:如何使用W3C sitemap.xsd驗證W3C網站地圖和谷歌地圖?

<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"> 

我有兩個sitemap文件。
1. W3C爬行頁文件,就像這樣:

<?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文件,像這樣:

<?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> 

我使用W3C sitemap.xsd通過xmllint驗證這兩個文件。
1. W3C stitemap文件,正常的和成功
2.谷歌-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 

我認爲,這個問題是命名空間是谷歌-的sitemap.xml和sitemap.xsd不同。 我應該怎麼辦使用sitemap.xsd來驗證這兩個sitemap文件?

謝謝!

回答

0

如果在google sitemap實例文檔中沒有對sitemaps.org站點地圖架構的引用,那麼我沒有看到你應該如何驗證它,甚至不知道你爲什麼要這樣做。

通過包括在文件的頂部的命名空間中,谷歌地圖實例清楚地說,它是google.com網站地圖架構的實例,而不是sitemaps.org網站地圖模式。

+0

每個文件的身體是完全一樣的。一個站點地圖文件包括 ...和這樣的標籤,我想通過一個xsd(模式)文件驗證這些文件,但我沒有做到這一點。如果我在Google站點地圖文件中刪除xmlns =「http://www.google.com/schemas/sitemap/0.9」,則驗證將會通過。 – Felix

+0

無論文件的正文如何,名稱空間屬性都會定義XML中類型的定義位置。如果你想驗證一個文件,聲明它的類型是在schemaA中定義的,但是使用schemaB,它將不起作用。 –

+0

哦,那麼糟糕。我想驗證這些xml忽略它們的命名空間聲明,你有什麼想法嗎?我使用xerces-c lib。 – Felix