It sounds like you want an element url (and all sub-elements) located in the space sitemap names, so you want to:
XNamespace ns = "http://www.sitemaps.org/schemas/sitemap/0.9"; XElement locElement = new XElement(ns + "loc", location); XElement lastmodElement = new XElement(ns + "lastmod", modifiedDate.ToString("yyyy-MM-dd")); XElement changefreqElement = new XElement(ns + "changefreq", changeFrequency); XElement urlElement = new XElement(ns + "url"); urlElement.Add(locElement); urlElement.Add(lastmodElement); urlElement.Add(changefreqElement);
or more conditionally for LINQ to XML:
XNamespace ns = "http://www.sitemaps.org/schemas/sitemap/0.9"; XElement urlElement = new XElement(ns + "url", new XElement(ns + "loc", location); new XElement(ns + "lastmod", modifiedDate.ToString("yyyy-MM-dd"), new XElement(ns + "changefreq", changeFrequency));
source share