Monday 7 April 2014

XmlDocument.CreateElement automatically adds xmlns="". How to get ride of it?

Problem:
 <?xml version="1.0" encoding="UTF-8"?>  
 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"   
  xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"   
  xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">  
  <url xmlns="">   
 .......................  
  </url>  
 </urlset>  

Solution:
When creating the url element, instead of using
 doc.CreateElement("url");  
use
 doc.CreateElement("url","http://www.sitemaps.org/schemas/sitemap/0.9");