Vbscript - 创建XML文件并添加命名空间

时间:2014-07-23 17:26:09

标签: xml vbscript

我正在尝试使用vbscript使用以下格式创建xml文件

<?xml version="1.0" encoding="UTF-8"?>
<products xmlns="http://www.myurl.com">
<product>
<url>http://www.link.com</url>
</product>

我能够添加“产品”,“产品”和“网址”的所有元素,但问题是我不知道如何将xmlns添加到products元素。

这是我的代码:

Set xmlDoc = CreateObject("Microsoft.XMLDOM")  
Set objRoot = xmlDoc.createElement("products")
xmlDoc.appendChild objRoot  

1 个答案:

答案 0 :(得分:1)

为节点创建属性xmlns

Set xmlDoc = CreateObject("Msxml2.DOMDocument.6.0")
Set objRoot = xmlDoc.createElement("products")

Set xmlns = xmlDoc.createAttribute("xmlns")
xmlns.text = "http://www.myurl.com"
objRoot.setAttributeNode xmlns

xmlDoc.appendChild objRoot
相关问题