Results 1 to 3 of 3

Thread: Something very cool... Take a look

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2000
    Posts
    219

    Cool

    You can read an xml file in an ado recordset:

    Code:
    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:
    Code:
    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?

  2. #2
    Fanatic Member Jerry Grant's Avatar
    Join Date
    Jul 2000
    Location
    Dorset, UK
    Posts
    810
    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:
    Code:
      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:
    Code:
    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.
    Jerry Grant................tnarG yrreJ
    Website: <JG-Design></.net>
    Email: [email protected]
    Working towards a bug free world......
    (Not a Microsoft employee)

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2000
    Posts
    219
    Thanks for the reply Jerry,


    Code:
    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width