ASP XML - Help Needed ?

Reply

Join Date: Aug 2006
Posts: 7
Reputation: karthikcyano is an unknown quantity at this point 
Solved Threads: 0
karthikcyano karthikcyano is offline Offline
Newbie Poster

ASP XML - Help Needed ?

 
0
  #1
Dec 13th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 4
Reputation: zhk is an unknown quantity at this point 
Solved Threads: 0
zhk zhk is offline Offline
Newbie Poster

Re: ASP XML - Help Needed ?

 
0
  #2
Dec 13th, 2007
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

%>
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC