title: How to serialize google sitemap in c# using XmlSerializer
body: <p>I want to serialize like this</p>
  
  <pre><code>&lt;urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
          xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"&gt;
  &lt;/urlset&gt;
  </code></pre>
  
  <p>But wrong result generated.</p>
  
  <p>My class is here</p>
  
  <pre><code>[Serializable]
  [XmlRoot("urlset")]    
  public class GoogleSiteMap
  {        
      public GoogleSiteMap() {
          xmlns = "http://www.sitemaps.org/schemas/sitemap/0.9";
          xmlnsNews = "http://www.google.com/schemas/sitemap-news/0.9";
          Urls = new List&lt;gUrlBase&gt;();
      }
  
      [XmlAttribute]
      public string xmlns { get; set; }
  
      [XmlAttribute("news",Namespace="xmlns")]
      public string xmlnsNews { get; set; }
  
      [XmlElement("url")]
      public List&lt;gUrlBase&gt; Urls { get; set; }
  }
  </code></pre>
  
  <p>Serializer is here</p>
  
  <pre><code>public static void GenerateGoogle(GoogleSiteMap smap,string filePath) {
  
          XmlSerializer ser = new XmlSerializer(typeof(GoogleSiteMap));
          using (FileStream fs = new FileStream(filePath, FileMode.Create))
          {
              ser.Serialize(fs, smap);
              fs.Close();
          }            
  
      }
  </code></pre>
  
  <p>Then result is here</p>
  
  <pre><code>&lt;urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:d1p1="xmlns" d1p1:news="http://www.google.com/schemas/sitemap-news/0.9"/&gt;
  </code></pre>
  
  <p><strong>What's wrong on my class declaration?</strong></p>
  
  <p><strong>Another  QUESTION 2</strong></p>
  
  <p>How can i declare like this</p>
  
  <pre><code>&lt;urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
          xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"&gt;
      &lt;url&gt;
          &lt;loc&gt;http://www.example.org/business/article55.html&lt;/loc&gt;
          &lt;news:news&gt;&lt;/news:news&gt;
      &lt;/url&gt;
      &lt;url&gt;
          &lt;loc&gt;http://www.example.org/business/page1.html&lt;/loc&gt;
          &lt;lastmod&gt;2010-10-10&lt;/lastmod&gt;
          &lt;changefreq&gt;weekly&lt;/changefreq&gt;
      &lt;/url&gt;
  &lt;/urlset&gt;
  </code></pre>
  
  <p>my declaration is here</p>
  
  <pre><code>[XmlRoot("urlset", Namespace = "http://www.sitemaps.org/schemas/sitemap/0.9")]
      public class GoogleSiteMap
      {
          public GoogleSiteMap()
          {
              Urls = new List&lt;gUrlBase&gt;();
          }
  
          //[XmlElement("url")]
          [XmlElement("url",Type = typeof(gNormalUrl))]
          [XmlElement("url",Type = typeof(gNewsUrl))]
          public List&lt;gUrlBase&gt; Urls { get; set; }
      }
  </code></pre>
  
  <p>This is return error</p>
  
  <p><code>The XML element 'url' from namespace 'http://www.sitemaps.org/schemas/sitemap/0.9' is already present in the current scope. Use XML attributes to specify another XML name or namespace for the element.</code></p>
  
  <p><strong>How can i declare Same root name "url"?</strong></p>