使用经典ASP创建sitemap.xml时出现urlset标记问题
我正在使用经典ASP创建sitemap.xml文件,但是我遇到了一个我无法解决的小问题。我的目标是遵守这一点: 我的输出中的问题。我不知道如何阻止在url标记中打印xmlns=“”。它应该只显示在urlset标记中 以下是剪切粘贴工作ASP/VBScript:使用经典ASP创建sitemap.xml时出现urlset标记问题,xml,asp-classic,sitemap,xmldom,Xml,Asp Classic,Sitemap,Xmldom,我正在使用经典ASP创建sitemap.xml文件,但是我遇到了一个我无法解决的小问题。我的目标是遵守这一点: 我的输出中的问题。我不知道如何阻止在url标记中打印xmlns=“”。它应该只显示在urlset标记中 以下是剪切粘贴工作ASP/VBScript: Dim theDom, theRoot, theParent,theChild, theID, docInstruction Set theDom = Server.CreateObject("Microsoft.XMLDOM") S
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")
这是它创建的XML文件的输出。如何阻止xmlns=”“显示在url标记中,但确保它保留在urlset标记中
<?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>
-
-
http://someURL.com
周报
-
http://someOtherUrl.com
周报
尝试使用CreateNode而不是CreateElement。如果将名称空间作为第三个参数传递,则xmlns属性不再添加到元素中。类似这样的东西对我很有用:
Dim theDom, theRoot, theParent,theChild, theID, docInstruction
const NODE_ELEMENT = 1
const xmlns = "http://www.sitemaps.org/schemas/sitemap/0.9"
Set theDom = Server.CreateObject("Microsoft.XMLDOM")
Set theRoot = theDom.createElement("urlset")
Set theID = theDom.createAttribute("xmlns")
theID.Text = xmlNs
theRoot.setAttributeNode theID
theDom.appendChild theRoot
Set theParent = theDom.createNode(NODE_ELEMENT, "url", xmlns)
Set theChild = theDom.createNode(NODE_ELEMENT, "loc", xmlns)
theChild.Text = "http://someURL.com"
theRoot.appendChild theParent
theParent.appendChild theChild
Set theChild = theDom.createNode(NODE_ELEMENT, "changefreq", xmlns)
theChild.Text = "weekly"
theRoot.appendChild theParent
theParent.appendChild theChild
Set theParent = theDom.createNode(NODE_ELEMENT, "url", xmlns)
Set theChild = theDom.createNode(NODE_ELEMENT, "loc", xmlns)
theChild.Text = "http://someOtherUrl.com"
theRoot.appendChild theParent
theParent.appendChild theChild
Set theChild = theDom.createNode(NODE_ELEMENT, "changefreq", xmlns)
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")
它生成以下输出:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://someURL.com</loc>
<changefreq>weekly</changefreq>
</url>
<url>
<loc>http://someOtherUrl.com</loc>
<changefreq>weekly</changefreq>
</url>
</urlset>
http://someURL.com
每周的
http://someOtherUrl.com
每周的
我看了又看,看不出是什么导致了我的问题。任何人如果xmlns=“”出现在url标签中甚至是一个问题,有人有意见吗?