Tôi đang tạo ra một sitemap.xml độngCách tạo thuộc tính xsi: schemalocation một cách chính xác khi tạo một sitemap.xml động với LINQ to XML?
Theo sitemaps.org đây là tiêu đề cho một sitemap.xml
<?xml version='1.0' encoding='UTF-8'?>
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
...
</url>
</urlset>
Vì vậy, tôi đang sử dụng LINQ to XML để tạo ra sitemap.xml
XNamespace ns = "http://www.sitemaps.org/schemas/sitemap/0.9";
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 new GetNodes()
select new XElement(ns + "url",
new XElement(ns + "loc", node.Loc),
new XElement(ns + "lastmod", node.LastMod),
new XElement(ns + "priority", node.Priority)
)
).ToString();
Dòng nhận xét là dòng tôi không thể nhận được đúng.
Làm cách nào tôi có thể đặt thuộc tính "xsi: schemalocation"?
Cảm ơn.
Để công bằng, nó không quan trọng một chút những gì các identifier không gian tên thực tế là. Nó có thể là "carlosmunoz" cho tất cả những gì quan trọng :) –
Cool, sau đó tôi sẽ sử dụng "carlosmunoz" –
Hey Carlos, phương thức 'GetNodes' trở lại là gì? Cảm ơn trước. – Ethan