[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

problem formatting xml file using Classic ASP code

Posted on 2012-08-13
2
Medium Priority
?
1,119 Views
Last Modified: 2012-09-06
I have classic asp code as shown in section (c) below:
It produces test.xml formatted as section (a) below:
How can I change the code to format test.xml as section (b) below:
also, only have one LoginDetails node?
also, where to put vbCrLf to produce new line after node is closed?
Thank you in advance for any help given.

(a) test.xml incorrect formatting in file:
<?xml version="1.0"?>
<LoginDetails><LoginDetails><Provider>sqloledb</Provider><Username>sa</Username><Password>H6web97!</Password><Server>Dinosaur1\sqlexpress</Server><Port>4096</Port><Database>AdminDB2</Database><Table>AdminTable</Table></LoginDetails></LoginDetails>

(b) test.xml with required formatting in file:
<?xml version="1.0"?>
<LoginDetails>
<Provider>sqloledb</Provider>
<Username>sa</Username>
<Password>H6web97!</Password>
<Server>Dinosaur1\sqlexpress</Server>
<Port>4096</Port>
<Database>AdminDB2</Database>
<Table>AdminTable</Table>
</LoginDetails>

(c) classic asp code:
<%
Dim tmpAccountName, xmlpath, blnFileExist, objXMLv, tmpClubID, tmpMemberNo, tmpPassword, xmlObj
xmlpath = server.MapPath("../Template/XML/" & tmpAccountName & "test.xml")
    set objXML = CreateObject("Microsoft.FreeThreadedXMLDOM")
        objXML.async = False
        blnFileExist = objXML.load(xmlpath)
        If not(blnFileExist) Then
            objXML.appendChild(objXML.createProcessingInstruction("xml","version=""1.0""" & vbCrLf))
            objXML.appendChild(objXML.createElement("LoginDetails"))
                Set objXMLv = objXML.createElement("LoginDetails")
                'Assign this node an ID, and give the ID a value
                'objXMLv.setAttribute "ID", tmpClubID
                objXMLv.appendChild(objXML.createElement("Provider"))
                objXMLv.appendChild(objXML.createElement("Username"))
                objXMLv.appendChild(objXML.createElement("Password"))
                objXMLv.appendChild(objXML.createElement("Server"))
                objXMLv.appendChild(objXML.createElement("Port"))
                objXMLv.appendChild(objXML.createElement("Database"))
                objXMLv.appendChild(objXML.createElement("Table"))
                objXMLv.childNodes(0).text = txtProvider
                objXMLv.childNodes(1).text = txtUsername
                objXMLv.childNodes(2).text = txtPassword
                objXMLv.childNodes(3).text = txtServer
                objXMLv.childNodes(4).text = PortTextBox
                objXMLv.childNodes(5).text = DatabaseTextBox
                objXMLv.childNodes(6).text = TableTextBox
                objXML.documentElement.appendChild(objXMLv.cloneNode(true))
                objXML.save(xmlpath)
          End If
    Set objXMLv = nothing
    Set xmlObj = nothing
%>
0
Comment
Question by:homeshopper
2 Comments
 
LVL 19

Accepted Solution

by:
zc2 earned 2000 total points
ID: 38305724
you could do that this way:

            Set objXMLv = objXML.createElement("LoginDetails")
            objXML.appendChild(objXMLv)
                set e = objXML.createElement("Provider")
                e.text = txtProvider
                objXMLv.appendChild(e)
                objXMLv.appendChild(objXML.createTextNode(vbCrLf))
                set e = objXML.createElement("Username")
                e.text = txtUsername
                objXMLv.appendChild( e )
                objXMLv.appendChild(objXML.createTextNode(vbCrLf))
                set e = objXML.createElement("Password")
                e.text = txtPassword
                objXMLv.appendChild( e )
                objXMLv.appendChild(objXML.createTextNode(vbCrLf))
                set e = objXML.createElement("Server")
                e.text = txtServer
                objXMLv.appendChild( e )
                objXMLv.appendChild(objXML.createTextNode(vbCrLf))
                set e = objXML.createElement("Port")
                e.text = PortTextBox
                objXMLv.appendChild( e )
                objXMLv.appendChild(objXML.createTextNode(vbCrLf))
                set e = objXML.createElement("Database")
                e.text = DatabaseTextBox
                objXMLv.appendChild( e )
                objXMLv.appendChild(objXML.createTextNode(vbCrLf))
                set e = objXML.createElement("Table")
                e.text = TableTextBox
                objXMLv.appendChild( e )
                objXMLv.appendChild(objXML.createTextNode(vbCrLf))

Open in new window

0
 

Author Comment

by:homeshopper
ID: 38309462
Thank you for your help, your method works well.
Below is the complete code for others to view:
Case "Write XML"
                                  txtProvider = Session("xtProvider")
              txtUsername = Session("xtUsername")
              txtPassword = Session("xtPassword")
              txtServer = Session("xtServer")
              PortTextBox = Session("xtPortTextBox")
              DatabaseTextBox = Session("xtDatabaseTextBox")
              TableTextBox = Session("xtTableTextBox")
          FileName2 = Session("FileName2")
          xmlpath = server.MapPath(FileName2)
          Dim e, tmpAccountName, xmlpath, blnFileExist, objXMLv, tmpClubID, tmpMemberNo, tmpPassword, xmlObj
          xmlpath = server.MapPath("../Template/XML/" & tmpAccountName & "test.xml")
          set objXML = CreateObject("Microsoft.FreeThreadedXMLDOM")
          objXML.async = False
          blnFileExist = objXML.load(xmlpath)
        If not(blnFileExist) Then
            objXML.appendChild(objXML.createProcessingInstruction("xml","version=""1.0""" & vbCrLf))
            Set objXMLv = objXML.createElement("LoginDetails")
                  objXML.appendChild(objXMLv)
                set e = objXML.createElement("Provider")
                e.text = txtProvider
                objXMLv.appendChild(e)
                objXMLv.appendChild(objXML.createTextNode(vbCrLf))
                set e = objXML.createElement("Username")
                e.text = txtUsername
                objXMLv.appendChild( e )
                objXMLv.appendChild(objXML.createTextNode(vbCrLf))
                set e = objXML.createElement("Password")
                e.text = txtPassword
                objXMLv.appendChild( e )
                objXMLv.appendChild(objXML.createTextNode(vbCrLf))
                set e = objXML.createElement("Server")
                e.text = txtServer
                objXMLv.appendChild( e )
                objXMLv.appendChild(objXML.createTextNode(vbCrLf))
                set e = objXML.createElement("Port")
                e.text = PortTextBox
                objXMLv.appendChild( e )
                objXMLv.appendChild(objXML.createTextNode(vbCrLf))
                set e = objXML.createElement("Database")
                e.text = DatabaseTextBox
                objXMLv.appendChild( e )
                objXMLv.appendChild(objXML.createTextNode(vbCrLf))
                set e = objXML.createElement("Table")
                e.text = TableTextBox
                objXMLv.appendChild( e )
                objXMLv.appendChild(objXML.createTextNode(vbCrLf))
            objXML.save(xmlpath)
          End If
    Set objXMLv = nothing
    Set xmlObj = nothing
     Case Default
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question