Hi, I am trying to create a google sitemap. But my url element which contains three other nodes always have an empty xmlns="" attribute.
This is causing a namespace error when submitting the sitemap.
Below is my code used to create the sitemap.
I would be glad if someone can help me have a url element without the xmlns attribute
I am trying to have this format:
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc></loc>
<lastmod></lastmod>
<changefreq></changefreq>
</url>
</urlset>
Currently it is like below:
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url xmlns="">
<loc></loc>
<lastmod></lastmod>
<changefreq></changefreq>
</url>
</urlset>
-------------
TryxmlDoc.Load("C:\sitemap.xml") Catch generatedExceptionName As System.IO.FileNotFoundException
'if file is not found, create a new xml file Dim xmlWriter As New XmlTextWriter("C:\sitemap.xml", System.Text.Encoding.UTF8)
xmlWriter.Formatting = Formatting.Indented
xmlWriter.WriteStartDocument()
xmlWriter.WriteStartElement("urlset")xmlWriter.WriteAttributeString("xmlns", "", Nothing, "http://www.sitemaps.org/schemas/sitemap/0.9")
xmlWriter.Close()
End TryxmlDoc.Load("C:\sitemap.xml")
Dim root As XmlNode = xmlDoc.DocumentElementDim childNode As XmlNode = xmlDoc.CreateElement("url")Dim locNode As XmlNode = xmlDoc.CreateElement("loc")
locNode.InnerText = url
childNode.AppendChild(locNode)
Dim lastModNode As XmlNode = xmlDoc.CreateElement("lastmod")
lastModNode.InnerText = dateOfNews
childNode.AppendChild(lastModNode)
Dim changeNode As XmlNode = xmlDoc.CreateElement("changefreq")
changeNode.InnerText = changeFreq
childNode.AppendChild(changeNode)
root.AppendChild(childNode)
xmlDoc.Save(
"C:\sitemap.xml")