问题
I have an XML Sitemap that needs to be rendered properly when accessed on a browser.
See code below.
<?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>
However, when I try accessing it on a browser, it only shows as plain text.
Any help/explanation why it renders as plain text is very much appreciated.
Thank you.
回答1:
So after many hours of googling and doing a lot of trial and errors, I managed to fix my problem with the help of this link: Google multilingual sitemap issue
By changing the declaration from this (using http://www.w3.org/1999/xhtml):
<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">
to this (using http://www.w3.org/TR/xhtml11/xhtml11_schema.html):
<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/TR/xhtml11/xhtml11_schema.html 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/TR/xhtml11/xhtml11_schema.html">
Now when the XML file is accessed on the browser, it now returns XML format and not plain text.
Hope this may help others in need. :)
来源:https://stackoverflow.com/questions/51923627/xml-sitemap-rendering-as-plain-text