我一直在搜索,但是似乎找不到有关此问题的任何信息。
如果您访问https://support.google.com/webmasters/answer/34648,则会显示必须将mobile标签添加到xml中才能正确抓取。我的问题在于,我不知道在使用XDocument时如何实际制作此标签。
有谁知道如何手动写这个标签
<mobile:mobile/>
使用XElement标签?
我有以下代码生成文档
XNamespace sitemap = XNamespace.Get("http://www.sitemaps.org/schemas/sitemap/0.9");
XNamespace mobile = XNamespace.Get("http://www.google.com/schemas/sitemap-mobile/1.0");
XDocument doc = new XDocument(
new XDeclaration("1.0", "utf-8", null),
new XElement(sitemap + "urlset",
new XAttribute(XNamespace.Xmlns + "mobile", mobile))
);
以及以下构建元素的代码
private XElement BuildSitemapItem(XNamespace ns)
{
XElement urlNode = new XElement(ns + "url",
new XElement(ns +"loc"),
new XElement(ns + "lastmod")
);
return urlNode;
}
我在这个问题上停留了一段时间,因此将不胜感激。
您只需要在XElement上指定正确的名称空间(在这种情况下为mobile)
XNamespace mobileNs = "http://www.google.com/schemas/sitemap-mobile/1.0";
new XElement(mobileNs + "mobile")
那将输出 <mobile:mobile/>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句