View Single Post
  #1 (permalink)  
Old April 16th, 2014, 01:09 AM
mat41 mat41 is offline
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default small issue creating sitemap.xml usinf ASP

Im using classic ASP to create sitemap.xml files however I am getting a small issue which I cant figure out. My objective is to obey this:

http://www.sitemaps.org/protocol.html

The issue in my output. I can not figure out how to stop the xmlns="" being printed inside the url tag. it should only be showing in the urlset tag

Here is the cut n paste working ASP/VBScript:

Code:
Dim theDom, theRoot, theParent,theChild, theID, docInstruction

Set theDom = Server.CreateObject("Microsoft.XMLDOM")
Set theRoot = theDom.createElement("urlset")

Set theID = theDom.createAttribute("xmlns")
theID.Text = "http://www.sitemaps.org/schemas/sitemap/0.9"
theRoot.setAttributeNode theID
theDom.appendChild theRoot

Set theParent = theDom.createElement("url")     
  Set theChild = theDom.createElement("loc")
  theChild.Text = "http://someURL.com"
  theRoot.appendChild theParent
  theParent.appendChild theChild

  Set theChild = theDom.createElement("changefreq")
  theChild.Text = "weekly"
  theRoot.appendChild theParent
  theParent.appendChild theChild

Set theParent = theDom.createElement("url")     
  Set theChild = theDom.createElement("loc")
  theChild.Text = "http://someOtherUrl.com"
  theRoot.appendChild theParent
  theParent.appendChild theChild

  Set theChild = theDom.createElement("changefreq")
  theChild.Text = "weekly"
  theRoot.appendChild theParent
  theParent.appendChild theChild

Set docInstruction = theDom.createProcessingInstruction("xml","version='1.0' encoding='UTF-8'")
theDom.insertBefore docInstruction, theDom.childNodes(0)
theDom.Save Server.MapPath("MyXMLDoc.xml")
and here is the output of the XML file it creates. How can I stop the xmlns="" from showing in the url tag but make sure it stays in the urlset tag??

Code:
  <?xml version="1.0" encoding="UTF-8" ?> 
 - <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  - <url xmlns="">
     <loc>http://someURL.com</loc> 
     <changefreq>weekly</changefreq> 
    </url>
 - <url xmlns="">
    <loc>http://someOtherUrl.com</loc> 
    <changefreq>weekly</changefreq> 
   </url>
  </urlset>
__________________
Wind is your friend
Matt

Last edited by mat41; April 16th, 2014 at 02:34 AM..
Reply With Quote