Benny Sutton is 4 hire - just click here
Google sitemap xml LINQpad
Here's a query you can run directly in LINQPad to create a google sitemap
Select language > C# Statement(s) on the LINQpad menu, connect your database and specify the table/fields in the code below
var styleInstruction = new XProcessingInstruction(
"xml-stylesheet", "href='styles.css' type='text/css'"
);
XNamespace Xname = "http://www.sitemaps.org/schemas/sitemap/0.9";
var docType = new XDocumentType("html",
"-//W3C//DTD XHTML 1.0 Strict//EN",
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd", null);
var categories =
new XElement(Xname + "urlset",
from c in Categories // specify your table name
select
new XElement("url",
new XElement("loc", "https://www.stockphotography.co.uk/categories/" + c.CategoryID + "-" + c.CategoryName), // specify your display fields
new XElement("lastmod", c.DateCreated.ToString("yyyy-MM-dd")) // this date format is vital
new XElement("changefreq", "monthly"),
new XElement("priority", 0.8)
)
);
var doc =
new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
categories
);
string tempPath = Path.Combine(Path.GetTempPath(), "sample.xml");
doc.Save (tempPath);
// This will display the page in IE or FireFox
Process.Start (tempPath);
// this will display contents of the xml file we just created in the pane below
File.ReadAllText (tempPath).Dump();
Conditional-queries-using-LINQpad