Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

xanburzum

[Resolvido] Dataset xmlString

Recommended Posts

Recuperar os dados de seu banco de dados como XML usando Dataset xmlString ou rotinas XMLDocument e apresentá-lo usando XSL Stylesheet,este exemplo usa OpenX v2.0 para MS SQL Server e banco de dados Microsoft. OpenX componente disponível em http

 

 

<%@ Language=VBScript %>
    <%
    Set oConn = Server.CreateObject("OpenX2.Connection")
    Set oCommand = Server.CreateObject("OpenX2.Command")
    Dim sResult, sSQL, sResultStr, sResultDoc
    Dim bError
    Dim i
    sSQL = "SELECT * FROM titles"
    On Error Goto 0
    Sub ProcessErr
    If Err.number <> 0 Then
    bError = true
    sResult = ""
    If oConn.ErrorCode <> 0 Then
    sResult = "Erro de conexão OpenX2: " & oConn.ErrorInfo & ". Error #" & oConn.ErrorCode & " (" & oConn.ErrorCodeEx & ")<br />"
    Else
    If oCommand.ErrorCode <> 0 Then
    sResult = "OpenX2 Erro de comando: " & oCommand.ErrorInfo & ". Error #" & oCommand.ErrorCode & " (" & oCommand.ErrorCodeEx & ")<br />"
    End If
    End If
    If sResult = "" Then
       sResult = "ASP Error: #" & CStr(Err.Number) & ". " & Err.description & "<br />"
    End If
    End If
    End Sub
    Sub ProcessQuery
    bError = false
    oConn.Connect("ms_ox1")
    oCommand.Connection = oConn
    oCommand.CommandText = sSQL
    sResultStr = oCommand.XMLString
    oCommand.Close()
    
    oCommand.CommandText = sSQL
    'Definir locais de estilo
    Dim styleFile
    Set xmlTmpl = Server.CreateObject("Msxml2.XSLTemplate.2.6")
    Set xslStyle = Server.CreateObject("Msxml2.FreeThreadedDOMDocument.2.6")
    styleFile = Server.MapPath("OpenX2.xsl")
    xslStyle.async = false
    xslStyle.load(styleFile)
    Set xmlTmpl.stylesheet = xslStyle
    Set xmlProc = xmlTmpl.createProcessor()
   
    xmlProc.input = oCommand.XMLDocument
    If xmlProc.transform() Then
    	sResultDoc = xmlProc.output
    End If
    End Sub
       On Error Resume Next
    ProcessQuery
    ProcessErr
    %>
    <html>
    <head><title>Saída XML</title></head>
    <%
    If Not bError Then
    %>
    <XML id="source"><%=sResultStr%></XML>
    <XML id="style" src="OpenX2.xsl"></XML>
    <script type="text/javascript" event="onload" for="window">
    showResult.innerHTML = source.transformNode(style.XMLDocument);
    </script>
    <%
    End If
    %>
    <body>
    <%
    If Not bError Then
    %>
    <h1>Server-Side XMLDocument Processing</h1>
    <div><%=sResultDoc%></div>
    <h1>Client-Side XML-Island (String) Processing</h1>
    <div id="showResult"></div>
    <%
    Else
    %>
    <div><%=sResultDoc%></div>
    <%
    End If
    %>
    <%= sResult %>
    </body>
    </html>
    XSL Style (OpenX2.xsl)
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    	<xsl:template match="RECORDSET">
    		<xsl:element name="table">
    			<xsl:for-each select="RECORD">
    				<xsl:element name="tr">
    					<xsl:for-each select="FIELD">
    						<xsl:element name="td">
    							<xsl:value-of select="."/>
    						</xsl:element>
    					</xsl:for-each>
    				</xsl:element>
    			</xsl:for-each>
    		</xsl:element>
    	</xsl:template>
    	<xsl:template match="/">
    		<xsl:apply-templates select="RECORDSET"/>
    	</xsl:template>
    	<xsl:template match="text()">
    		<xsl:value-of select="."/>
    	</xsl:template>
    </xsl:stylesheet>

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.