• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2076
  • Last Modified:

VBScript - creating an xml document

Hello,

I am trying to create an xml document with vbscript code.  

Here is the code:
Dim objXML , objProduct, objVariant
Set objXML = Server.CreateObject("Microsoft.XMLDOM")

Set objXML.documentElement = objXML.createElement("xmlImportFile")

Set objProduct = objXML.createElement("Product")
objProduct.appendChild objXML.createElement("Name")
objProduct.appendChild objXML.createElement("Other")
objProduct.childNodes(0).text = "somename"
objProduct.childNodes(1).text = "othercontent"
Set objVariant = objXML.createElement("ProductVariant")
objVariant.appendChild objXML.createElement("Price")
objVariant.childNodes(0).text = "0.00"
objXML.documentElement.appendChild objProduct.cloneNode(true)
objXML.documentElement.appendChild objVariant.cloneNode(true)

*************************************************
Here is the current XML result:

<xmlImportFile>
     <Product>
      <Name>somename</Name>
      <Other>othercontent</Other>
     </Product>
     <ProductVariant>
      <Price>0.00</Price>
     </ProductVariant>
</xmlImportFile>

*************************************************
This is WHAT I NEED for XML output:

<xmlImportFile>
     <Product>
      <Name>somename</Name>
      <Other>othercontent</Other>

     <ProductVariant>
      <Price>0.00</Price>
     </ProductVariant>
     </Product>
</xmlImportFile>

*************************************************
Notice the location of the closing product tag.


Any help would be appreciated!!!!!
0
craptastic
Asked:
craptastic
1 Solution
 
peterxlaneCommented:
<%
Dim objXML , objProduct, objVariant
Set objXML = Server.CreateObject("Microsoft.XMLDOM")

Set objXML.documentElement = objXML.createElement("xmlImportFile")

Set objProduct = objXML.createElement("Product")
objProduct.appendChild objXML.createElement("Name")
objProduct.appendChild objXML.createElement("Other")
objProduct.childNodes(0).text = "somename"
objProduct.childNodes(1).text = "othercontent"

Set objVariant = objXML.createElement("ProductVariant")
objVariant.appendChild objXML.createElement("Price")
objVariant.childNodes(0).text = "0.00"
objProduct.appendChild objVariant

objXML.documentElement.appendChild objProduct
%>
0
 
craptasticAuthor Commented:
perfect, thanks!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now