2016-11-22 28 views

回答

1

使用可以使用System.Xml.Linq

public ContentResult GetSiteMap() 
{ 
    XNamespace ns = "http://www.sitemaps.org/schemas/sitemap/0.9"; 
    XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance"; 
    return new XElement(ns + "urlset", 
     new XAttribute("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9"), 
     new XAttribute(XNamespace.Xmlns + "xsi", "http://www.w3.org/2001/XMLSchema-instance"), 
     new XAttribute(xsi + "schemaLocation", "http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"), 
     from node in db.MyTable() 
     select new XElement(ns + "url", 
      new XElement(ns + "loc", node.Loc), 
      new XElement(ns + "lastmod", node.LastMod), 
      new XElement(ns + "priority", node.Priority) 
     ) 
    ).ToString(); 
    return Content(xsi.ToString(), "text/xml"); 
} 
+0

親愛的,它會在db.MyTable()中的節點上發出錯誤,就像您可以使用表格作爲方法一樣。你能告訴我嗎? PLZ –

+0

Thanks Got Point .... –

+0

你需要改變db.MyTable()連接到你的表(使用Linq) – Yanga

相關問題