Tips for generating XML in SQL Server 2000

Source: Internet
Author: User
Tags xml parser

This article describes a small technique for generating XML in SQL Server 2000.

In the previous introduction of SQL2K has been mentioned in the SQL2K of XML support, using the FOR XML statement can easily translate the results of execution into an XML, which can greatly improve the efficiency of the system and development speed, the detailed content see books Online.

But the way the XML returned is accessed using ADO (Required ADO 2.6) is different from the original recordset. If you still use the recordset, you can only get an XML Schema in Unicode format without getting the content of the XML.

In fact, this problem is very easy to solve, but I think I am very familiar with ADO, did not look at help carefully, so did not find ADO is the way to get and return XML stream.

The Command object has two properties, called input stream and output stream, and the value of the property is an IUnknown interface. You can assign an XML parser interface to it, or use the request, response, etc. directly. The advantage is that there is no need to generate a recordset, save the data, and thus save the system overhead.

Here's a simple example to return XML with response:

<%@ Language=VBScript %>
<!-- #include file="ADOVBS.inc" -->
<%
 Dim objConn, objCmd, i
 Set objConn = Server.createobject("ADODB.CONNECTION")
 objConn.Open "Provider=SQLOLEDB.1;Password=;
Persist Security Info=True;User ID=sa;Initial Catalog=PBA;Data Source=(local)"
 Set objCmd = Server.CreateObject("ADODB.Command")
 objCmd.ActiveConnection = objConn
 objCmd.Properties("Output Stream") = Response
 objCmd.Properties("XML Root") = "root"
 objCmd.CommandText = "Select * from UserStatus for XML Auto"
 Response.ContentType = "text/xml"
 objCmd.Execute i, , adExecuteStream
 Set objCmd = Nothing
 objConn.Close
 Set objConn = Nothing
%>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.