C# 用于将站点地图绑定在一起的XML架构

C# 用于将站点地图绑定在一起的XML架构,c#,asp.net,xml,xsd,sitemap,C#,Asp.net,Xml,Xsd,Sitemap,我有以下定义XML模式的代码。在保持线路连接方面有问题。以前工作得很好 public static FileContentResult WriteTo(SiteMapFeed feedToFormat) { var siteMap = feedToFormat; //TODO: DO something, next codes are just DEMO var header = "<?xml version=\"1.0\" encoding=

我有以下定义XML模式的代码。在保持线路连接方面有问题。以前工作得很好

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");
} 
publicstaticfilecontentresult写入(sitemapfeedtoformat)
{
var siteMap=feedToFormat;
//TODO:做点什么,接下来的代码只是演示
var header=“”
+Environment.NewLine+“”;
var url=new System.Text.StringBuilder();
foreach(siteMap.Items中的var站点)
{
URL.Append(string.Format(“http://www.{0}/{1}{2}{3},site.Url,site.LastMod,site.ChangeFreq,site.Priority);
}                    
byte[]fileContent=System.Text.Encoding.UTF8.GetBytes(header+url+“”);
返回新的FileContentResult(fileContent,“text/xml”);
} 
因此,这会导致以下错误:

我哪里做错了?谢谢

我认为问题在于“xsi:schemaLocation”这一点——如果我的大脑没有记错的话,XML属性中的引号之间不可能有多行。尝试更改为:

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;
var header=“”
+Environment.NewLine+“”+Environment.NewLine;