| | |
ASP XML - Help Needed ?
Please support our ASP advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
![]() |
•
•
Join Date: Dec 2007
Posts: 4
Reputation:
Solved Threads: 0
I have used this code to export database fields.
It is quite simple if you like to use. Hope this helps!
<%@ Language=VBScript %>
<% option explicit %>
<%
'Response.ContentType = "text/xml"
'Response.Write "<?xml version='1.0' ?>"
dim RS, CN, xmlstr, mydoc
set CN = server.CreateObject("adodb.connection")
set RS = server.CreateObject("adodb.recordset")
' where passwd = '' Response.Write "<?xml-stylesheet type='text/xsl' href='report.xsl'?>"
CN.ConnectionString = "dsn=ODBC-DataSourceName; uid=userid; password=password"
CN.Open
RS.Open "select empid, firstname, lastname, email from employee order by lastname",cn
xmlstr = "<?xml version='1.0' ?>"
xmlstr = xmlstr & "<ROOT>"
xmlstr = xmlstr & RS2XML(RS,"EMPLOYEE")
xmlstr = xmlstr & "</ROOT>"
Set mydoc = server.CreateObject("microsoft.xmldom")
mydoc.loadxml(xmlstr)
if mydoc.parseError.errorcode <> 0 then
response.Write("There is an Error loading the XML <br> ")
response.Write("<br> parse error code -> " & mydoc.parseError.errorcode)
response.Write("<br> parse error reason:---> " & mydoc.parseError.reason)
else
'response.write xmlstr <---- commented out - just for testing the output
mydoc.save(Server.MapPath("outputfile.xml"))
response.Write("Output file stored to the disk")
end if
CN.close
set rs = nothing
set cn = nothing
function RS2XML(rs, ChildNode)
dim Field
if rs is nothing then exit function
ChildNode = ucase(ChildNode)
if rs.eof then
RS2XML = ""
exit function
end if
do until rs.eof
if ChildNode <> "" then RS2XML = RS2XML & "<" & ChildNode & ">"
for each field in rs.fields
RS2XML = RS2XML & " <" & ucase(field.name) & ">" & server.HTMLEncode(NotNull(field.value)) & "</" & ucase(field.name) & ">"
next
if ChildNode <> "" then RS2XML = RS2XML & "</" & ChildNode & ">"
rs.movenext
loop
end function
Function NotNull(vOrig)
If(IsNull(vOrig)) then
NotNull = ""
else
NotNull = vOrig
end if
End Function
%>
It is quite simple if you like to use. Hope this helps!
<%@ Language=VBScript %>
<% option explicit %>
<%
'Response.ContentType = "text/xml"
'Response.Write "<?xml version='1.0' ?>"
dim RS, CN, xmlstr, mydoc
set CN = server.CreateObject("adodb.connection")
set RS = server.CreateObject("adodb.recordset")
' where passwd = '' Response.Write "<?xml-stylesheet type='text/xsl' href='report.xsl'?>"
CN.ConnectionString = "dsn=ODBC-DataSourceName; uid=userid; password=password"
CN.Open
RS.Open "select empid, firstname, lastname, email from employee order by lastname",cn
xmlstr = "<?xml version='1.0' ?>"
xmlstr = xmlstr & "<ROOT>"
xmlstr = xmlstr & RS2XML(RS,"EMPLOYEE")
xmlstr = xmlstr & "</ROOT>"
Set mydoc = server.CreateObject("microsoft.xmldom")
mydoc.loadxml(xmlstr)
if mydoc.parseError.errorcode <> 0 then
response.Write("There is an Error loading the XML <br> ")
response.Write("<br> parse error code -> " & mydoc.parseError.errorcode)
response.Write("<br> parse error reason:---> " & mydoc.parseError.reason)
else
'response.write xmlstr <---- commented out - just for testing the output
mydoc.save(Server.MapPath("outputfile.xml"))
response.Write("Output file stored to the disk")
end if
CN.close
set rs = nothing
set cn = nothing
function RS2XML(rs, ChildNode)
dim Field
if rs is nothing then exit function
ChildNode = ucase(ChildNode)
if rs.eof then
RS2XML = ""
exit function
end if
do until rs.eof
if ChildNode <> "" then RS2XML = RS2XML & "<" & ChildNode & ">"
for each field in rs.fields
RS2XML = RS2XML & " <" & ucase(field.name) & ">" & server.HTMLEncode(NotNull(field.value)) & "</" & ucase(field.name) & ">"
next
if ChildNode <> "" then RS2XML = RS2XML & "</" & ChildNode & ">"
rs.movenext
loop
end function
Function NotNull(vOrig)
If(IsNull(vOrig)) then
NotNull = ""
else
NotNull = vOrig
end if
End Function
%>
![]() |
Similar Threads
- C#/ASP.Net Developer Needed (Web Development Job Offers)
- learning php (PHP)
- Parse Error Assitance Needed (PHP)
- xml appending (C#)
- Help needed in simple app while using XML,XSL (XML, XSLT and XPATH)
- Simple ASP.Net Login Page (Using VB.Net) (ASP.NET)
- Final yr project an opinion needed on "dynamic web pg creator" (Computer Science)
- JScript experts - HELP needed! (Java)
Other Threads in the ASP Forum
- Previous Thread: File Upload in MySQL Database with ASP
- Next Thread: CDOSYS Form to Email Formatting
| Thread Tools | Search this Thread |
archive asp aspandmssqlserver2005 aspandmssqlserver2005connection aspconnection connection database databaseconnection dreamweaver excel fso msmsql mssql2005 mssqlserver2005 mssqlserver2005andasp mssqlserverandasp opentextfile record searchbox selectoption single specfic sqlserver sqlserverconnection





