Search code examples
vbscriptasp-classic

Variable when writing XML - Classic ASP


I have the below code, how would i replace the '1' within the below with a variable ?

Set objorderline1 = objXML.createElement("OrderLine")

Set objorderline1att = objXML.createAttribute("xmlns")

objorderline1att.text = ""

objorderline1.setAttributeNode objorderline1att

objorder.appendChild objorderline1

e.g. Set objlinenumber(linenumber) = objXML.createElement("LineNumber")

objlinenumber(linenumber).text = linenumber

objorderline(linenumber).appendChild objlinenumber(linenumber)

Set objproduct(linenumber) = objXML.createElement("Product")

I want to be able to loop through a table of products from the database and create separate nodes for each product in the XML.

Thank you


Solution

  • Building the string then adding that variable into the code works as expected. Quite a straight forward one but here is the solution.

    s = "objorderline" & linenumber
    t = "objorderlineatt" & linenumber
    ln = "objlinenumber" & linenumber
    pr = "objproduct" & linenumber
    
    
    Set s = objXML.createElement("OrderLine")
        Set t = objXML.createAttribute("xmlns")
        t.text = ""
        s.setAttributeNode t
        objorder.appendChild s
    
    
        Set ln = objXML.createElement("LineNumber")
        ln.text = linenumber
        s.appendChild ln
        Set pr = objXML.createElement("Product")