p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Classic ASP Professional (http://p2p.wrox.com/forumdisplay.php?f=63)
-   -   small issue creating sitemap.xml usinf ASP (http://p2p.wrox.com/showthread.php?t=92652)

mat41 April 16th, 2014 01:09 AM

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>


Imar April 22nd, 2014 05:46 AM

Hi Matt,

I answered this question here: http://stackoverflow.com/questions/2...15919#23215919

Cheers,

Imar


All times are GMT -4. The time now is 06:41 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.