[英]XML Schema for Sitemap binding it together
I have the following code for defining XML Schema. 我有以下代码用于定义XML模式。 Having a problem in keeping the lines together. 在保持线条一致方面存在问题。 Worked fine before. 以前工作得很好。
public static FileContentResult WriteTo(SiteMapFeed feedToFormat)
{
var siteMap = feedToFormat;
//TODO: DO something, next codes are just DEMO
var header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ Environment.NewLine + "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\""
+ Environment.NewLine + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
+ Environment.NewLine + "xsi:schemaLocation=\""
+ Environment.NewLine + "http://www.sitemaps.org/schemas/sitemap/0.9"
+ Environment.NewLine + "http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\">";
var urls = new System.Text.StringBuilder();
foreach (var site in siteMap.Items)
{
urls.Append(string.Format("<url><loc>http://www.{0}/</loc><lastmod>{1}</lastmod><changefreq>{2}</changefreq><priority>{3}</priority></url>", site.Url, site.LastMod, site.ChangeFreq, site.Priority));
}
byte[] fileContent = System.Text.Encoding.UTF8.GetBytes(header + urls + "</urlset>");
return new FileContentResult(fileContent, "text/xml");
}
SO this is now causing the following error: 因此,这现在导致以下错误:
Where am I doing it wrong? 我在哪里做错了? Thanks 谢谢
Problem is in that "xsi:schemaLocation" bit I think - you can't have multiple lines between quotes in an XML attribute, if my brain remembers correctly. 问题在于我认为“ xsi:schemaLocation”位-如果我的大脑正确记住,则XML属性中的引号之间不能有多行。 Try changing to: 尝试更改为:
var header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ Environment.NewLine + "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\""
+ Environment.NewLine + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
+ Environment.NewLine + "xsi:schemaLocation=\""
+ "http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\">" + Environment.NewLine;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.