简体   繁体   中英

Vbscript - Creating an XML file and Adding Namespace

I'm trying to use vbscript to create a xml file using the following format

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

I was able to add all the elements for "products", "product" and "url", but the problem is that I don't know how to add the xmlns to the products element.

Here is my code:

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

Create an attribute xmlns for the node:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM