Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML Newbie question about creating XML file from asp 1

Status
Not open for further replies.

a0f6459

Programmer
Dec 5, 2007
13
US
Hi,

I've been asked to create an xml file that will mirror the information currently pulled by an .asp page I have created. As an example, this .asp page uses a stored procedure to pull customer information and displays it on a page. What I want to do is for the page to pull the same information, but also write it to an .xml file. Here is what I have so far can anyone tell me if I am on the right track as I can't seem to get it to work. Please note that this code is used in the very same .asp file.

Code:
<%

dim xmlDoc
dim xmlPI
dim nodeRoot
dim bankNode
dim rtNode
dim phoneNode
dim alt_phoneNode
dim aru_phoneNode


'Instantiate the Microsoft XMLDOM.
 Set xmlDoc = Server.CreateObject("MICROSOFT.XMLDOM")
 xmlDoc.preserveWhiteSpace = True

'Create root  
 Set nodeRoot = xmlDoc.createElement("check_info")
 xmlDoc.appendChild nodeRoot
 

'Create the required nodes

   Set bankNode = xmlDoc.createElement("bank")
   Set rtNode = xmlDoc.createElement("rt")
   Set phoneNode = xmlDoc.createElement("phone")
   Set alt_phoneNode = xmlDoc.createElement("alt_phone")
   Set aru_phoneNode = xmlDoc.createElement("aru_phone")

'Assign the variables

   bankNode.text = bankname
   rtNode.text = rt
   phoneNode.text= phone
   alt_phoneNode.text = alt_phone
   aru_phoneNode.text = aru_phone
   
   
   nodeRoot.appendChild(bankNode)
   nodeRoot.appendChild(rtNode)
   nodeRoot.appendChild(phoneNode)
   nodeRoot.appendChild(alt_phoneNode)
   nodeRoot.appendChild(aru_phoneNode) 

 'Create the xml processing instruction.
 Set xmlPI = xmlDoc.createProcessingInstruction("xml", "version='1.0'")

 'Append the processing instruction to the XML document.
 xmlDoc.insertBefore xmlPI, xmlDoc.childNodes(0)

 'Save the XML document.
   xmlDoc.save("Person.xml")

 'Release all of your object references.
 Set xmlDoc = Nothing
 Set xmlPI = Nothing
 Set nodeRoot = Nothing
 Set bankNode = Nothing
 Set rtNode = Nothing
 Set phoneNode = Nothing
 Set alt_phoneNode = Nothing   
 Set aru_phoneNode  = Nothing  
   
%>
 
>xmlDoc.save("Person.xml")
[tt]xmlDoc.save server.mappath("Person.xml")[/tt]
 
Thanks, let me clarify. I have an .asp page that is called earlier that defines the path.

My error currently is this:


Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: 'text'

This error is referring to

aru_phoneNode.text = aru_phone

I'm not sure if this has anything to do with that fact that this field is a number in the database table.

 
aru_phone cannot be other than a string. For instance, it can be empty, it cannot be null, it cannot be an array etc.

However, the use of server.mappath() in my above post is a must. You cannot get away with it in any other way. Those non-disclosed variables, I am not answerable to.
 
Ok, so if the aru_phone variable is a number, what do I need to do to convert it so that it can written in the xml file?
 
It should be fine for number, ok? It should not be null, mind you, that's the biggest possibility. Test it.
[tt]
if not isnull(aru_phone) then
aru_phoneNode.text = aru_phone
else
aru_phoneNode.text = ""
end if
[/tt]
Of course, if it is an array say, the above is not sufficient.
 
Ok, I see what you are saying and you were right, the variable contained a null value. Now that is resolved and I have added in server.mappath(). Now I get this error on that particular line:

msxml3.dll (0x80070005)
Access is denied.

I'm not sure what I need to do to be able create the file. Any ideas as far as this error goes?
 
Check whether write permission is granted to IUSR_machinename account on the folder in question. Details you have to ask iis or asp forums.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top