显示SQL Server的XML输出 [英] Display XML Output from SQL Server

查看:85
本文介绍了显示SQL Server的XML输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个连接到SQL Server 2000 db的asp.net(1.1)应用程序。我在$ db中有一个存储过程,它以xml格式输出数据。

我需要做的是显示我从我的

存储过程并将其显示在我想要的格式化的网页中。

我设法让我的xml显示为我希望如果我手动运行我的

在QA中存储proc并将xml复制到记事本中并将其保存为Test.xml。我在这个xml文件中引用了我的xsl文件,当我在IE中查看这个文件时,它会显示我希望它的



我需要知道的是如何以编程方式执行此操作。我可以从db获取我的

xml数据。我只需要帮助将数据传输到我可以显示的页面中。


谢谢

I have an asp.net (1.1) application that connects to a SQL server 2000 db. I
have a stored procedure in my db that out puts data in xml format.
What I need to be able to do is display that xml that I retrieve from my
stored proc and display it in a web page formatted as I want.
I have managed to get my xml to display as I wish if I manually run my
stored proc in QA and copy the xml into notepad and save it as Test.xml. I
reference my xsl file in this xml file and when I view this file in IE it
displays as I want it to.

What I need to know is how to do this programmatically. I am able to get my
xml data from the db. I just need help with transferring that data into a
page that I can display.

Thanks

推荐答案




Terry Holland写道:


Terry Holland wrote:
我有一个asp.net(1.1)应用程序连接到SQL Server 2000 db。我在我的数据库中有一个存储过程,它以xml格式输出数据。
我需要做的是显示我从我的
存储过程中检索的xml并显示它在我想要的格式化的网页中。
如果我在QA中手动运行我的
存储过程并将xml复制到记事本并将其保存为测试,我已设法让我的xml显示。 XML。我在这个xml文件中引用了我的xsl文件,当我在IE中查看这个文件时,它会显示我想要的内容。

我需要知道的是怎么做以编程方式。我能从db获取我的
xml数据。我只需要帮助将数据传输到我可以显示的页面。
I have an asp.net (1.1) application that connects to a SQL server 2000 db. I
have a stored procedure in my db that out puts data in xml format.
What I need to be able to do is display that xml that I retrieve from my
stored proc and display it in a web page formatted as I want.
I have managed to get my xml to display as I wish if I manually run my
stored proc in QA and copy the xml into notepad and save it as Test.xml. I
reference my xsl file in this xml file and when I view this file in IE it
displays as I want it to.

What I need to know is how to do this programmatically. I am able to get my
xml data from the db. I just need help with transferring that data into a
page that I can display.




ASP.NET有一个XML控件,允许您应用转换,请参阅

< http://msdn.microsoft.com/library/default.asp?url = / library / en-us / cpref / html / frlrfSystemWebUIWebControlsXmlClassTopic.asp>


我不确定它是否适合帮助您显示

查询结果。您可以简单地编写转换代码

自己创建一个XslTransform实例

< http://msdn.microsoft.com/library/default.asp?url = /library/en-us/cpref/html/frlrfSystemXmlXslXslTransformClassTopic.asp>

并使用其Transform方法。

Transform方法的输入可以是一个XPathDocument而不是

执行查询后得到的XmlReader

< http://msdn.microsoft.com/library/default.asp?url = / library / en-us / cpref / html / frlrfSystemDataSqlClientSqlCommandClassExecuteXmlR eaderTopic.asp>

-

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/


我看过你指示我的例子但我还不清楚。


我会举一个例子,说明我想要做的事情,或许你是

可以告诉我我需要做什么将我的数据显示在网页上(并且

可能保存为新的xml文件)。

当我浏览到webform1.aspx时,我想显示来自我的

存储过程TestXML使用xsl文件NW.xsl并保存为文件

在Web目录中的OutputDDMMYYYY.xml。


提前致谢


我有一个名为NW.xsl的xsl文件

================ ====

<?xml version =" 1.0" encoding =" ISO-8859-1"?>

< xsl:stylesheet version =" 1.0"

xmlns:xsl =" http:/ /www.w3.org/1999/XSL/Transform">

< xsl:template match =" /">

< html>

< body>

< table border =" 1">

< xsl:for-each select =" ROOT / CU">

< tr>

< td colspan =" 2">< xsl:value-of select =" CU_CN" / >< / td>

< / tr>

< xsl:for-each select =" ORD">

< tr>

< td>< xsl:value-of select =" ORD_ID" />< / td>

< td> < xsl:value-of select =" ORD_DATE" />< / td>

< / tr>


< xsl: for-each select =" OD"

< tr>

< td>< xsl:value-of select =" OD_UP" /> ;< / td>

< td>< xsl:value-of select =" OD_QTY&qu ot; />< / td>

< / tr>

< / xsl:for-each>

< / xsl:for-each>

< / xsl:for-each>

< / table>

< / body>

< / html>

< / xsl:template>


< / xsl:stylesheet>

====================


我创建了一个名为TestXML的存储过程

==================================

SELECT

dbo.Customers.CompanyName,

dbo.Orders.OrderID,

dbo.Orders.OrderDate,

dbo。[订购]详情] .UnitPrice,

dbo。[订单详情] .Quantity,

dbo.Products.ProductName,

dbo.Products.QuantityPerUnit


来自

dbo.Customers INNER JOIN

dbo.Orders ON dbo.Customers.CustomerID = dbo.Orders.CustomerID INNER JOIN

dbo。[订单详情] ON dbo.Orders.OrderID = dbo。[订单详情]。订购商

INNER JOIN

dbo.Products在dbo。[O rder详细信息] .ProductID = dbo.Products.ProductID


for xml auto,elements

============== ====================


在我的页面webform1.aspx上使用以下函数GetData

在Form_Load上调用

==================================== ========

函数GetData()作为XPathDocument''XmlReader

Dim SqlConnection1 As System.Data.SqlClient.SqlConnection

Dim SqlCommand1 As System.Data.SqlClient.SqlCommand


SqlConnection1 = New System.Data.SqlClient.SqlConnection

SqlCommand1 = New System.Data.SqlClient。 SqlCommand

SqlConnection1.ConnectionString =" user id = WebUser; data

source = TERRY; initial catalog = Northwind"

SqlConnection1.Open( )


SqlCommand1.CommandText =" TestXML"

SqlCommand1.CommandType = System.Data.CommandType.StoredProcedure

SqlCommand1。 Connection = SqlConnection1


Dim o As XmlReader = SqlCommand1.ExecuteXmlReader


''不知道该怎么做

结束功能


" Martin Honnen" <毫安******* @ yahoo.de>在消息中写道

news:eb ************** @ TK2MSFTNGP04.phx.gbl ...
Ive looked at the examples you directed me to but Im still unclear.

I''ll give an example of the type of thing Im trying to do and perhaps you
could tell me what I need to do to get my data displayed on a web page (and
possibly saved as a new xml file).
When I browse to webform1.aspx I would like to display the output from my
stored procedure TestXML using the xsl file NW.xsl and saved as a file
OutputDDMMYYYY.xml in the web directory.

Thanks in advance

I have a xsl file called NW.xsl
====================
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<table border="1">
<xsl:for-each select="ROOT/CU">
<tr>
<td colspan="2"><xsl:value-of select="CU_CN"/></td>
</tr>
<xsl:for-each select="ORD">
<tr>
<td><xsl:value-of select="ORD_ID"/></td>
<td><xsl:value-of select="ORD_DATE"/></td>
</tr>

<xsl:for-each select="OD">
<tr>
<td><xsl:value-of select="OD_UP"/></td>
<td><xsl:value-of select="OD_QTY"/></td>
</tr>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>
====================

I have created a stored procedure called TestXML
==================================
SELECT
dbo.Customers.CompanyName,
dbo.Orders.OrderID,
dbo.Orders.OrderDate,
dbo.[Order Details].UnitPrice,
dbo.[Order Details].Quantity,
dbo.Products.ProductName,
dbo.Products.QuantityPerUnit

FROM
dbo.Customers INNER JOIN
dbo.Orders ON dbo.Customers.CustomerID = dbo.Orders.CustomerID INNER JOIN
dbo.[Order Details] ON dbo.Orders.OrderID = dbo.[Order Details].OrderID
INNER JOIN
dbo.Products ON dbo.[Order Details].ProductID = dbo.Products.ProductID

for xml auto, elements
==================================

On my page webform1.aspx with the following function GetData
that gets called on Form_Load
============================================
Function GetData() As XPathDocument '' XmlReader
Dim SqlConnection1 As System.Data.SqlClient.SqlConnection
Dim SqlCommand1 As System.Data.SqlClient.SqlCommand

SqlConnection1 = New System.Data.SqlClient.SqlConnection
SqlCommand1 = New System.Data.SqlClient.SqlCommand
SqlConnection1.ConnectionString = "user id=WebUser;data
source=TERRY;initial catalog=Northwind"
SqlConnection1.Open()

SqlCommand1.CommandText = "TestXML"
SqlCommand1.CommandType = System.Data.CommandType.StoredProcedure
SqlCommand1.Connection = SqlConnection1

Dim o As XmlReader = SqlCommand1.ExecuteXmlReader

''not sure what to do here
End Function

"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:eb**************@TK2MSFTNGP04.phx.gbl...

< Terry Holland写道:


Terry Holland wrote:
我有一个asp.net(1.1)应用程序连接到SQL服务器2000
db。我在我的数据库中有一个存储过程,它以xml格式输出数据。
我需要做的是显示我从我的
存储过程中检索的xml并将其显示在网页中格式化我想要的。如果我在QA中手动运行我存储的
proc并将xml复制到记事本并将其保存为Test.xml,我已设法让我的xml显示为我希望的。我在这个xml文件中引用了我的xsl文件,当我在IE中查看这个文件时,它会显示我想要的内容。我需要知道的是如何以编程方式执行此操作。我可以从db获取我的xml数据。我只需要帮助将数据传输到我可以显示的页面中。
I have an asp.net (1.1) application that connects to a SQL server 2000
db. I have a stored procedure in my db that out puts data in xml format.
What I need to be able to do is display that xml that I retrieve from my
stored proc and display it in a web page formatted as I want. I have
managed to get my xml to display as I wish if I manually run my stored
proc in QA and copy the xml into notepad and save it as Test.xml. I
reference my xsl file in this xml file and when I view this file in IE it
displays as I want it to. What I need to know is how to do this
programmatically. I am able to get my xml data from the db. I just need
help with transferring that data into a page that I can display.



ASP.NET有一个XML控件,允许您应用转换,请参阅
< http://msdn.microsoft.com/library/default.asp? url = / library / en-us / cpref / html / frlrfSystemWebUIWebControlsXmlClassTopic.asp>

然而我不确定它非常适合帮助您显示
查询结果。您可以简单地编写转换代码
自己创建一个XslTransform实例
< http://msdn.microsoft.com/library/default.asp?url = / library / en-us / cpref /html/frlrfSystemXmlXslXslTransformClassTopic.asp>
并使用其Transform方法。
Transform方法的输入可以是通过执行查询得到的XmlReader上的XPathDocument
< http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataSqlClientSqlCommandClassExecuteXmlR eaderTopic.asp>

-

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/



我看过你指示我的例子,但我还不清楚。


我我会给出一个我尝试做的事情的例子,也许你可以告诉我需要做些什么才能让我的数据显示出来在一个网页上(和

可能保存为新的xml文件)。

当我浏览webform1.aspx时,我想显示我的输出
存储过程TestXML使用xsl文件NW.xsl并保存为文件

在Web目录中的OutputDDMMYYYY.xml。


谢谢提前


我有一个名为NW.xsl的xsl文件

====================

<?xml version =" 1.0" encoding =" ISO-8859-1"?>

< xsl:stylesheet version =" 1.0"

xmlns:xsl =" http:/ /www.w3.org/1999/XSL/Transform">

< xsl:template match =" /">

< html>

< body>

< table border =" 1">

< xsl:for-each select =" ROOT / CU">

< tr>

< td colspan =" 2">< xsl:value-of select =" CU_CN" / >< / td>

< / tr>

< xsl:for-each select =" ORD">

< tr>

< td>< xsl:value-of select =" ORD_ID" />< / td>

< td> < xsl:value-of select =" ORD_DATE" />< / td>

< / tr>


< xsl: for-each select =" OD"

< tr>

< td>< xsl:value-of select =" OD_UP" /> ;< / td>

< td>< xsl:value-of select =" OD_QTY&qu ot; />< / td>

< / tr>

< / xsl:for-each>

< / xsl:for-each>

< / xsl:for-each>

< / table>

< / body>

< / html>

< / xsl:template>


< / xsl:stylesheet>

====================


我创建了一个名为TestXML的存储过程

==================================

SELECT

dbo.Customers.CompanyName,

dbo.Orders.OrderID,

dbo.Orders.OrderDate,

dbo。[订购]详情] .UnitPrice,

dbo。[订单详情] .Quantity,

dbo.Products.ProductName,

dbo.Products.QuantityPerUnit


来自

dbo.Customers INNER JOIN

dbo.Orders ON dbo.Customers.CustomerID = dbo.Orders.CustomerID INNER JOIN

dbo。[订单详情] ON dbo.Orders.OrderID = dbo。[订单详情]。订购商

INNER JOIN

dbo.Products在dbo。[O rder详细信息] .ProductID = dbo.Products.ProductID


for xml auto,elements

============== ====================


在我的页面webform1.aspx上使用以下函数GetData

在Form_Load上调用

==================================== ========

函数GetData()作为XPathDocument''XmlReader

Dim SqlConnection1 As System.Data.SqlClient.SqlConnection

Dim SqlCommand1 As System.Data.SqlClient.SqlCommand


SqlConnection1 = New System.Data.SqlClient.SqlConnection

SqlCommand1 = New System.Data.SqlClient。 SqlCommand

SqlConnection1.ConnectionString =" user id = WebUser; data

source = TERRY; initial catalog = Northwind"

SqlConnection1.Open( )


SqlCommand1.CommandText =" TestXML"

SqlCommand1.CommandType = System.Data.CommandType.StoredProcedure

SqlCommand1。 Connection = SqlConnection1


Dim o As XmlReader = SqlCommand1.ExecuteXmlReader


''不知道该怎么做

结束功能


" Martin Honnen" <毫安******* @ yahoo.de>在消息中写道

news:eb ************** @ TK2MSFTNGP04.phx.gbl ...
Ive looked at the examples you directed me to but Im still unclear.

I''ll give an example of the type of thing Im trying to do and perhaps you
could tell me what I need to do to get my data displayed on a web page (and
possibly saved as a new xml file).
When I browse to webform1.aspx I would like to display the output from my
stored procedure TestXML using the xsl file NW.xsl and saved as a file
OutputDDMMYYYY.xml in the web directory.

Thanks in advance

I have a xsl file called NW.xsl
====================
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<table border="1">
<xsl:for-each select="ROOT/CU">
<tr>
<td colspan="2"><xsl:value-of select="CU_CN"/></td>
</tr>
<xsl:for-each select="ORD">
<tr>
<td><xsl:value-of select="ORD_ID"/></td>
<td><xsl:value-of select="ORD_DATE"/></td>
</tr>

<xsl:for-each select="OD">
<tr>
<td><xsl:value-of select="OD_UP"/></td>
<td><xsl:value-of select="OD_QTY"/></td>
</tr>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>
====================

I have created a stored procedure called TestXML
==================================
SELECT
dbo.Customers.CompanyName,
dbo.Orders.OrderID,
dbo.Orders.OrderDate,
dbo.[Order Details].UnitPrice,
dbo.[Order Details].Quantity,
dbo.Products.ProductName,
dbo.Products.QuantityPerUnit

FROM
dbo.Customers INNER JOIN
dbo.Orders ON dbo.Customers.CustomerID = dbo.Orders.CustomerID INNER JOIN
dbo.[Order Details] ON dbo.Orders.OrderID = dbo.[Order Details].OrderID
INNER JOIN
dbo.Products ON dbo.[Order Details].ProductID = dbo.Products.ProductID

for xml auto, elements
==================================

On my page webform1.aspx with the following function GetData
that gets called on Form_Load
============================================
Function GetData() As XPathDocument '' XmlReader
Dim SqlConnection1 As System.Data.SqlClient.SqlConnection
Dim SqlCommand1 As System.Data.SqlClient.SqlCommand

SqlConnection1 = New System.Data.SqlClient.SqlConnection
SqlCommand1 = New System.Data.SqlClient.SqlCommand
SqlConnection1.ConnectionString = "user id=WebUser;data
source=TERRY;initial catalog=Northwind"
SqlConnection1.Open()

SqlCommand1.CommandText = "TestXML"
SqlCommand1.CommandType = System.Data.CommandType.StoredProcedure
SqlCommand1.Connection = SqlConnection1

Dim o As XmlReader = SqlCommand1.ExecuteXmlReader

''not sure what to do here
End Function

"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:eb**************@TK2MSFTNGP04.phx.gbl...

< Terry Holland写道:


Terry Holland wrote:
我有一个asp.net(1.1)应用程序连接到SQL服务器2000
db。我在我的数据库中有一个存储过程,它以xml格式输出数据。
我需要做的是显示我从我的
存储过程中检索的xml并将其显示在网页中格式化我想要的。如果我在QA中手动运行我存储的
proc并将xml复制到记事本并将其保存为Test.xml,我已设法让我的xml显示为我希望的。我在这个xml文件中引用了我的xsl文件,当我在IE中查看这个文件时,它会显示我想要的内容。我需要知道的是如何以编程方式执行此操作。我可以从db获取我的xml数据。我只需要帮助将数据传输到我可以显示的页面中。
I have an asp.net (1.1) application that connects to a SQL server 2000
db. I have a stored procedure in my db that out puts data in xml format.
What I need to be able to do is display that xml that I retrieve from my
stored proc and display it in a web page formatted as I want. I have
managed to get my xml to display as I wish if I manually run my stored
proc in QA and copy the xml into notepad and save it as Test.xml. I
reference my xsl file in this xml file and when I view this file in IE it
displays as I want it to. What I need to know is how to do this
programmatically. I am able to get my xml data from the db. I just need
help with transferring that data into a page that I can display.



ASP.NET有一个XML控件,允许您应用转换,请参阅
< http://msdn.microsoft.com/library/default.asp? url = / library / en-us / cpref / html / frlrfSystemWebUIWebControlsXmlClassTopic.asp>

然而我不确定它非常适合帮助您显示
查询结果。您可以简单地编写转换代码
自己创建一个XslTransform实例
< http://msdn.microsoft.com/library/default.asp?url = / library / en-us / cpref /html/frlrfSystemXmlXslXslTransformClassTopic.asp>
并使用其Transform方法。
Transform方法的输入可以是通过执行查询得到的XmlReader上的XPathDocument
< http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataSqlClientSqlCommandClassExecuteXmlR eaderTopic.asp>

-

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/



这篇关于显示SQL Server的XML输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆