我正在尝试将语言添加到我的sitemap.xml文件中,但是我得到"未定义链接上的名称空间前缀xhtml"错误.我该如何定义它?我在谷歌上找不到任何有用的东西.
这是文件:
<?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"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<!-- created with Free Online Sitemap Generator www.xml-sitemaps.com -->
<url>
<loc>https://www.leepio.dk/</loc>
</urlset>
Run Code Online (Sandbox Code Playgroud) 生成多种语言的站点地图:
按照 Google 的指示:
https://support.google.com/webmasters/answer/189077?hl=en
此代码:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" 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">
<url>
<loc>https://www.example.com</loc>
<lastmod>${formattedDate}</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
</urlset>
Run Code Online (Sandbox Code Playgroud)
结果(在浏览器中呈现):
此代码(带有xhtml:link标签):
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" 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">
<url>
<loc>https://www.example.com</loc>
<lastmod>${formattedDate}</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
<xhtml:link rel="alternate" hreflang="en-us" href="https://www.example.com"/>
<xhtml:link rel="alternate" hreflang="en-ca" href="https://ca.example.com"/>
<xhtml:link rel="alternate" hreflang="en-gb" href="https://uk.example.com"/>
</url>
</urlset>
Run Code Online (Sandbox Code Playgroud)
结果(在浏览器中呈现):
问题
似乎没有任何错误。但奇怪的是它没有像往常一样在浏览器中呈现 XML“页面”。
来自 Google的 https://www.google.com/gmail/sitemap.xml似乎也具有相同的行为(您可以检查它并看到响应包含一堆xhtml:link标签)。
我做错了什么还是添加这些标签时的正常行为xhtml:link?
我有一个XML Sitemap,在浏览器中访问时需要正确呈现。
请参见下面的代码。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<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/1999/xhtml 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/1999/xhtml"
>
<url>
<loc>https://www.brideonline.ru/_____PassioanteLady.html</loc>
<xhtml:link rel="alternate" hreflang="ru-us" href="https://www.brideonline.ru/profile.php?Language=Russian&ID=_____PassioanteLady&Language1=1"/>
<changefreq>monthly</changefreq>
<priority>0.1</priority>
</url>
<url>
<loc>https://www.brideonline.ru/___Alisa___.html</loc>
<xhtml:link rel="alternate" hreflang="ru-us" href="https://www.brideonline.ru/profile.php?Language=Russian&ID=___Alisa___&Language1=1"/>
<changefreq>monthly</changefreq>
<priority>0.1</priority>
</url>
</urlset>
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试在浏览器上访问它时,它仅显示为纯文本。
非常感谢任何帮助/解释为何将其呈现为纯文本。
谢谢。