Click to See Complete Forum and Search --> : Something very cool... Take a look
Shafee
Feb 18th, 2001, 08:51 PM
You can read an xml file in an ado recordset:
Set rst = Server.CreateObject("ADODB.Recordset")
rst.Open "myfile.xml", "Provider=MSPersist"
That's it.
Now, I was just wondering if it is possible to use it in asp. I know that the first line has to be:
Response.ContenType = "TEXT/XML"
I don't know how to output the actual XML recordset from the server.
If I can do that, I can make a disconnected recordset at the client side. Any ideas?
Jerry Grant
Feb 19th, 2001, 05:31 AM
What you need to do is 'Transform' the XML data with XSLT (eXtensible Stylesheet Langage Transformation). This outputs HTML code to send to the browser.
The best way to do this is to create a COM component (ActiveX DLL) to run on your server, which will send an XML Stream to your ASP page. Then, if the browser is XML aware (IE5 NS6), then you only need to append your XSL file reference to the start of the XML file:
Response.Write "<?xml-stylesheet type='text/xsl' href='myStylesheet.xsl'?>" & strXML
If the target browser is not XML aware then the 'Transformation' needs to be done on the server: this is a function in the ActiveX DLL:
Public Function ApplyXSL( _
ByVal strXMLfile As String, _
ByVal strXSLfile As String _
) As String
Dim strXMl As String
Dim objXML As MSXML2.DOMDocument
Dim strXSL As String
Dim objXSL As MSXML2.DOMDocument
'// Load the XML
Set objXML = New MSXML2.DOMDocument
strXMl = App.Path & "\" & strXMLfile
objXML.Load strXMl
'// Load the XSL
Set objXSL = New MSXML2.DOMDocument
strXSL = App.Path & "\" & strXSLfile
objXSL.Load strXSL
'// Transform to html
ApplyXSL = objXML.transformNode(objXSL)
Set objXML = Nothing
Set objXSL = Nothing
End Function
This assumes you have made a reference to the MSXML2.DLL in your ActiveX DLL project.
What I do, is build the XML file myself in the DLL, from a plain ADO recordset, and adding additional XML tags wher appropriate, when I want to validate the data first. This exports as a string from the DLL. This allows all of the ADO schema for the recorset to be ignored in the XML data, so the delivered data is cleaner and more structured for my XSL transformation.
I would suggest you use something like XMLSpy to try out this process, then adding the finished XSL files into ASP project.
:cool:
Shafee
Feb 20th, 2001, 04:58 AM
Thanks for the reply Jerry,
Response.ContentType = "TEXT/XML"
Set con = Server.CreateObject("ADODB.Connection")
Set rst = Server.CreateObject("ADODB.Recordset")
Set stm = Server.CreateObject("ADODB.Stream")
con.Open "dsn=MyDSN"
rst.CursorType = 3
rst.Open "MyTable", con
'Now it is possible to save my recordset to the stream object like this:
rst.Save stm
'Is there any way to save it directly to the response object?
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.