Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 6th, 2004, 03:53 AM
Registered User
 
Join Date: Oct 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Thebravehearth
Default retrieve data from SQL server wih XML

Hi all...

i'm newbie here..:)
yesterday i tried, to retrieve data from db SQL Server with XML.
this is the the code ... (prodtest.asp)


<%@ Language=VBScript%>
<%Server.ScriptTimeout=21478836%>
<%Response.Buffer=false%>
<%

dim objStream
dim objConn
dim objComm
dim objXML

set objStream = Server.CreateObject("ADODB.Stream")
set objConn = Server.CreateObject("ADODB.Connection")
set objComm = Server.CreateObject("ADODB.Command")
set objXML = Server.CreateObject("MSXML2.DOMDocument")

objConn.Open "Provider=SQLOLEDB; Data Source=intradka2; Initial Catalog=myProducts; UId=user; Pwd="
objComm.ActiveConnection = objConn

objComm.CommandText = "exec [dbo].sp_GetExplicitXML"
objStream.Open
objComm.Properties("Output Stream").Value = objStream
objComm.Execute , , 1024 'adExecuteStream = 1024
objStream.Position = 0
objXML.LoadXML("<?xml version='1.0'?><?xml-stylesheet type='text/xsl' href='prodtest.xsl'?><My_Products>" & objStream.ReadText & "</My_Products>")
if objXML.parseError.errorCode <> 0 then
 Response.Write "Error loading XML: " & objXML.parseError.reason
 Response.End
end if
Response.ContentType = "text/xml"
Response.Write objXML.xml

   Set objComm = Nothing
   objConn.Close
   Set objConn = Nothing

%>


[blue] and the XSL file is [/bue]


<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/TRANSFORM">
<xsl:template match="/">
<html>
<head>
<title> Sample Products </title>
</head>
<body>
<h1>Books in Catalog</h1>
<table border="0" cellspacing="2" cellpadding="3">
<xsl:for-each select="My_Products/Category">
<tr>
<td width="100%" bgcolor="#C0FFC0">
<xsl:value-of select="@CatName"/>
</td>
</tr>
<xsl:for-each select="Product">
<tr>
<td width="100%" bgcolor="#E9E9E9">
 <p style="margin-left:30"><xsl:value-of select="@ProdName"/></p>
</td>
</tr>
</xsl:for-each>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


if i run this page with IE so i dont get the record
and if i run this page with MOzilla, i get error like this
size=3]ERROR LOADING STYLESHEET : PARSING AN XSLT STYLESHEET FAILED[/SIZE]

so... what's the matter in code.....

thx 4 ur advice






&lt;b&gt;~TAT TWAM ASI~&lt;/b&gt;
 
Old October 6th, 2004, 07:23 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Difficult to debug this. What is returned by the command if you just display it without tring to add the processing instruction.
I would load the xml returned by the server and transform it via the stylesheet on the server before sending it to browser. If you must use the linked stylesheet approach then add the PI dynamically using the DOM and then save the result to the Response stream:
Code:
Response.ContentType = "text/xml" 
objXML.save Response



--

Joe (Co-author Beginning XML, 3rd edition)
 
Old October 6th, 2004, 08:49 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

I agree with Joe, do your transform at the server-side.

For info you can retrieve the XML from SQL Server directly into an XML DOM object, there's no need to go via an ADO Stream. Instead of this code:

objStream.Open
objComm.Properties("Output Stream").Value = objStream
objComm.Execute , , 1024 'adExecuteStream = 1024
objStream.Position = 0
objXML.LoadXML("<?xml version='1.0'?><?xml-stylesheet type='text/xsl' href='prodtest.xsl'?><My_Products>" & objStream.ReadText & "</My_Products>")

You would need:

objComm.Properties("Output Stream").Value = objXML
objComm.Properties("XML Root") = "My_Products"
objComm.Execute , , 1024 'adExecuteStream = 1024

hth
Phil
 
Old October 7th, 2004, 02:07 AM
Registered User
 
Join Date: Oct 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Thebravehearth
Default

thank alot my friends..

i gets ur ide...
i can solve this problem know .... :)

see you in another question ....

&lt;b&gt;~TAT TWAM ASI~&lt;/b&gt;





Similar Threads
Thread Thread Starter Forum Replies Last Post
Not able to retrieve data from SQL Server abhishekkashyap27 C# 2005 1 February 11th, 2008 09:19 AM
using oledb to retrieve data from sql server w A2K nikesierra2306 Access VBA 0 October 20th, 2004 04:36 PM
XML from SQL Server data spinout XML 5 September 25th, 2004 05:18 AM
inser xml data to sql server from asp ak Classic ASP Databases 7 February 25th, 2004 01:05 PM
inserting some data from xml file to sql server ak Classic ASP XML 1 February 25th, 2004 10:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.