Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The prefix '' cannot be redefined from '' to 'http://www.sitemaps.org/schemas/sitemap/0.9' within the same start element tag

I'm getting this error

The prefix '' cannot be redefined from '' to 'http://www.sitemaps.org/schemas/sitemap/0.9' within the same start element tag

while running this code

Dim writer As XmlWriter = XmlWriter.Create(FileLocation + "StaticUrls3.xml")
Dim urlList As New List(Of String)

urlList.Add("link1")
urlList.Add("link2")
urlList.Add("link3")       

writer.WriteStartDocument()
writer.WriteStartElement("urlset")
writer.WriteAttributeString("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9")

For Each aUrl As String In urlList
    writer.WriteStartElement("url")
    writer.WriteElementString("loc", aUrl)
    writer.WriteEndElement()
Next

writer.WriteEndElement()
writer.WriteEndDocument()
writer.Close()

Why am I getting this error?

like image 269
umarali1 Avatar asked Sep 27 '10 16:09

umarali1


1 Answers

Try this:

Const siteMapNamespace As String = "http://www.sitemaps.org/schemas/sitemap/0.9"
Dim writer As XmlWriter = XmlWriter.Create(FileLocation + "StaticUrls3.xml")
Dim urlList As New List(Of String)

urlList.Add("link1")
urlList.Add("link2")
urlList.Add("link3")       

writer.WriteStartDocument()
writer.WriteStartElement("urlset", siteMapNamespace)

For Each aUrl As String In urlList
    writer.WriteStartElement("url", siteMapNamespace)
    writer.WriteElementString("loc", aUrl)
    writer.WriteEndElement()
Next

writer.WriteEndElement()
writer.WriteEndDocument()
writer.Close()
like image 50
Markis Avatar answered Oct 16 '22 04:10

Markis