我想在ASP.NET MVC項目中創建一個站點地圖。如何將一點XML插入到使用Visual Basic的XDocument中?
這段代碼在我的節點控制器...
Function Sitemap() As ContentResult
Dim db As New EfrDotOrgEntities
Dim Nodes = db.Node.ToList
Dim RequestUrl As Uri = Url.RequestContext.HttpContext.Request.Url
Dim AbsoluteRoot As String = String.Format("{0}://{1}", RequestUrl.Scheme, RequestUrl.Authority)
Dim map As XDocument = <?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
</urlset>
For Each n As Node In Nodes
map.Add(<url>
<loc><%= AbsoluteRoot + Url.RouteUrl("IdOnly", New With {.id = n.Id}) %></loc>
</url>)
Next
Return Content(map.ToString, "text/xml", Encoding.UTF8)
End Function
(這裏是一個形象,因爲堆棧溢出不着色VB代碼以及)
...產生這個錯誤:
This operation would create an incorrectly structured document.
它不會知道wh添加該內容。
如何告訴它將該位的XML插入<urlset>
?
This works。謝謝! – 2009-05-01 12:19:22
我一直在努力! – MattGWagner 2009-11-13 21:38:31