You need to use the correct namespace:
[XmlRoot("urlset", Namespace = "http://www.sitemaps.org/schemas/sitemap/0.9")]
you can select the xmlns and xmlnsNews - they do something else. Likewise, any data in " http://www.google.com/schemas/sitemap-news/0.9 " should be flagged as such. Regardless of whether the news namespace alias is irrelevant (this is just an alias), it can be controlled with XmlSerializerNamespaces if you like. You do not need [Serializable] .
For example, if each <url> must be in the http://www.google.com/schemas/sitemap-news/0.9 namespace and you want to use " http://www.sitemaps.org/schemas/sitemap/0.9 "as a common namespace and http://www.google.com/schemas/sitemap-news/0.9 " aliased as "news", then:
static class Program { static void Main() { var ns = new XmlSerializerNamespaces(); ns.Add("", "http://www.sitemaps.org/schemas/sitemap/0.9"); ns.Add("news", "http://www.google.com/schemas/sitemap-news/0.9"); var ser = new XmlSerializer(typeof (GoogleSiteMap)); var obj = new GoogleSiteMap {Urls = new List<string> {"abc", "def", "ghi"}}; ser.Serialize(Console.Out, obj, ns); } } [XmlRoot("urlset", Namespace = "http://www.sitemaps.org/schemas/sitemap/0.9")] public class GoogleSiteMap { [XmlElement("url", Namespace = "http://www.google.com/schemas/sitemap-news/0.9")] public List<string> Urls { get; set; } }
This generates:
<urlset xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <news:url>abc</news:url> <news:url>def</news:url> <news:url>ghi</news:url> </urlset>
(I did not check what the namespaces of the actual content are - it is just to show the relationship between namespaces in data, namespaces in xml and namespace aliases)
Repeat your editing - something like:
static class Program { static void Main() { var ns = new XmlSerializerNamespaces(); ns.Add("", "http://www.sitemaps.org/schemas/sitemap/0.9"); ns.Add("news", "http://www.google.com/schemas/sitemap-news/0.9"); var ser = new XmlSerializer(typeof (GoogleSiteMap)); var obj = new GoogleSiteMap {Urls = { new SiteUrl { Location = "http://www.example.org/business/article55.html", News = ""}, new SiteUrl { Location = "http://www.example.org/business/page1.html", LastModified = new DateTime(2010,10,10), ChangeFrequency = "weekly"} }}; ser.Serialize(Console.Out, obj, ns); } } [XmlRoot("urlset", Namespace = "http://www.sitemaps.org/schemas/sitemap/0.9")] public class GoogleSiteMap { private readonly List<SiteUrl> urls = new List<SiteUrl>(); [XmlElement("url")] public List<SiteUrl> Urls { get { return urls; } } } public class SiteUrl { [XmlElement("loc")] public string Location { get; set; } [XmlElement("news", Namespace = "http://www.google.com/schemas/sitemap-news/0.9")] public string News { get; set; } [XmlElement("lastmod")] public DateTime? LastModified { get; set; } [XmlElement("changefreq")] public string ChangeFrequency { get; set; } public bool ShouldSerializeLastModified() { return LastModified.HasValue; } }
which generates:
<urlset xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <url> <loc>http://www.example.org/business/article55.html</loc> <news:news /> </url> <url> <loc>http://www.example.org/business/page1.html</loc> <lastmod>2010-10-10T00:00:00</lastmod> <changefreq>weekly</changefreq> </url> </urlset>