Hi to All,

I want to Export an Report to XML format from ASP. Herewith i also want to include the XSLT (i mean the stylesheet) also. Can anyone provide me the Sample code.

Thanks in Advance,
Karthik.

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

%>

This article has been dead for over six months. Start a new discussion instead.