That course is Course 2091A, Building XML-Enabled Applications Using Microsoft SQL Server 2000.. Familiarize yourself with Course 2091A, Building XML-Enabled Applications Using Microsoft
Trang 1Contents
Overview 1
Lesson: XML Support in SQL Server 2000 2
Lesson: Using HTTP to Access and Input
Lab 9: Creating SQL Queries Using XML 17
Review 22
Module 9: SQL XML
Trang 2Information in this document, including URL and other Internet Web site references, is subject to change without notice Unless otherwise noted, the example companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events depicted herein are fictitious, and no association with any real company, organization, product, domain name, e-mail address, logo, person, places or events is intended or should be inferred Complying with all applicable copyright laws is the responsibility of the user Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft Corporation Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this document Except as expressly provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property
2001 Microsoft Corporation All rights reserved
Microsoft, MS-DOS, Windows, Windows NT, ActiveX, BackOffice, bCentral, BizTalk, FrontPage, MSDN, MSN, Netshow, PowerPoint, SharePoint, Visio, Visual Basic, Visual C++, Visual C#, Visual InterDev, Visual Studio, Windows Media, and Xbox are either registered trademarks or trademarks of Microsoft Corporation in the U.S.A and/or other countries The names of actual companies and products mentioned herein may be the trademarks of their respective owners
Trang 3Instructor Notes
This module provides participants with an introduction to the use of Extensible Markup Language (XML) with Microsoft® SQL Server™ 2000
SQL Server 2000 is one of the Microsoft NET Enterprise Servers As such, it
is an example of how all the NET Enterprise Servers are changing to fully support XML technologies
This chapter will give participants an understanding of the diversity of XML support in SQL Server without overwhelming them This is a complex topic and might not be easily understood by all participants at first
Make certain that participants know that this module covers a major topic and that there is an entire course devoted to it That course is Course 2091A,
Building XML-Enabled Applications Using Microsoft SQL Server 2000
After completing this module, participants will be able to:
! Describe how SQL Server 2000 uses XML
! Describe how to implement XML support in SQL Server 2000
! Write basic XML queries against SQL Server 2000 by using Hypertext Transfer Protocol (HTTP)
! Use a basic XML template against SQL Server 2000 to retrieve data
! Insert data into SQL Server 2000 by using XML
! Describe some of the XML features recently added to SQL Server 2000
Presentation:
30 Minutes
Lab:
45 Minutes
Trang 4Materials and Preparation
This section provides the materials and preparation tasks that you need to teach this module
To teach this module, you need the following materials:
• Microsoft PowerPoint® file 2500A_09.ppt
To prepare for this module:
! Read all of the materials indicated for this module and complete all labs and practices
! Read the topic “XML and Internet Support” in SQL Server 2000 Books Online
! Familiarize yourself with Course 2091A, Building XML-Enabled Applications Using Microsoft SQL Server 2000 Note the differences
between the XML support described in the course and the XML support in the XML for SQL Server 2000 add-in
Instructor Setup for a Lab
This section provides setup instructions that are required to prepare the instructor computer or classroom configuration for a lab
! Prepare for the lab
1 Be sure that Internet Information Services (IIS) is properly configured and working
2 Be sure that Configure SQL XML Support in IIS is available in the Microsoft SQL Server program group menu
3 Work through as many examples as you can in addition to the lab exercises, because the participants may ask questions about what else can be done with XML and SQL queries
According to the Manual Setup Guide, the SQL password is set to 2500
Trang 5Demonstration
This section provides demonstration procedures that will not fit in the margin notes or are not appropriate for the student notes
! Prepare for the demonstration
1 Be sure that you have read and practiced the steps required to successfully install XML support for IIS
2 Be sure that you are familiar with the various properties pages for configuring a virtual directory
3 Test the setup and configuration, and make sure that it will properly process
a Uniform Resource Locator (URL) query and return the results to the browser properly
4 If you discover any problems with the configuration, be sure to fix them before you give the demonstration, because it can be time consuming to resolve them
! Set up the virtual directory in IIS to publish a SQL Server database
1 Click Start, point to All Programs, point to Microsoft SQL Server, and then click Configure SQL XML Support in IIS
2 Expand your server, right-click Default Web Site, point to New, and then click Virtual Directory
3 In the New Virtual Directory Properties dialog box, on the General tab, make Nwind09 the value for the Virtual Directory Name setting
4 Click Browse, browse to \Inetpub\wwwroot\ to select the local path, and then click Make New Folder
5 Type NwindSite and then click OK
6 On the Security tab, select Use Windows Integrated Authentication
7 On the Data Source tab, use the following settings and values
Trang 6! Set up the schema and template virtual names on IIS
1 Open Microsoft Windows® Explorer, and then navigate to the
5 In the Type list, click template
6 Click the ellipsis button (…), browse to the
\Inetpub\wwroot\NwindSite\templates folder, and then click OK
7 In the Virtual Name Configuration dialog box, click Save
8 Repeat steps 3 through 7 Use schema09 for the virtual name, schema for the type, and browse to the schemas folder
9 Close the New Virtual Directory Properties dialog box
10 Close the IIS Virtual Directory Management for SQL Server console
! Prepare for the demonstration
1 Read the documentation on the XML View Mapper and familiarize yourself with its architecture, purpose, and functionality
2 Practice the tutorial carefully more than once
3 To present this demonstration, use the tutorial to show how the XML View Mapper works The steps are not reproduced here You might want to print out the tutorial section of the XML View Mapper documentation
The XML View Mapper
Trang 7Module Strategy
This module represents a wide range of topics In many ways, it does not cover them sufficiently That is why there is a full course on this topic, which is now partially out of date due to the XML for SQL Server 2000 add-in Stress that this is strictly an overview of the topic, which is consistent with the overall nature of this course as an introduction Use the following strategy to present this module:
! XML Support in SQL Server 2000 This lesson gives the reasons for having XML support in SQL Server 2000 and the major capabilities of XML support in SQL Server 2000
! Using HTTP to Access and Input XML Data This lesson describes the power of using XML and SQL in queries through Hypertext Transfer Protocol (HTTP) access to SQL Server Be ready to explain why this capability is interesting and useful
Discuss the security risk of allowing direct URL queries One risk is that URL queries expose database structure Another risk is that identity of the issuer of the request may not be known For these reasons, limit the use of URL queries
Contrast allowing direct URL queries with using XML Path Language (XPath) and XML Schema Definitions (XSD) schemas This approach has
an important security advantage over allowing URL queries Template files enhance security by hiding details of the database schema from the end user The following lessons are included in Appendix C
! FOR XML and OpenXML
In this lesson, you see two methods of querying SQL Server 2000 by using tools available through the XML for SQL Server 2000 add-in
! Manipulating XML Using Transact-SQL This lesson shows participants how Transact-SQL and XML are useful and powerful when used together This can take up a lot of the module time, so move through it briskly
! Retrieving XML Data with ADO and ADO.NET This lesson is a quick overview The topic is too large for this course, and there is not time to cover the topic in more depth If you have time and are able to, elaborate on the evolution from ADO to ADO.NET Be prepared for questions, and be ready to provide examples Remind participants that there
is an ADO.NET course
! Using Mapping Schemas Explain why mapping is useful and how it fits in with other products and technologies, particularly Microsoft BizTalk™ Server 2000 Emphasize the importance of graphical tools like BizTalk Server Also, emphasize that tools like BizTalk Server are new and will become more sophisticated and friendly for the developer and user
Appendix
Trang 8! Updategrams and Bulk Load Updategrams and the Bulk Load utility are relatively straightforward, but be sure to explain why they are needed Because this topic can be slightly confusing, be prepared to give additional examples or to elaborate on the ones provided Read the background materials on these topics
! Ideas and Future of XML and SQL The purpose of this topic is to emphasize that SQL XML is developing rapidly The map example shows a different way to use XML and SQL Server together
Stress that Microsoft is enhancing XML support in SQL Server The speed
of the evolution of the Internet and the development of NET caused Microsoft to release the XML for SQL Server 2000 add-in, rather than wait for an entire product cycle Check the SQL Server site and the Microsoft MSDN® SQL Server site before each class to see if any new XML and SQL enhancements or product add-ins are announced
Trang 9Overview
***************************** ILLEGAL FOR NON - TRAINER USE ******************************
Microsoft® SQL Server™ 2000 plays a crucial role in the Microsoft NET strategy as a means of enabling the easy use of data with Extensible Markup Language (XML) technologies
This module presents a detailed overview of the implementation of XML in SQL Server 2000 and add-ins to the product since its release in 2000 Key points are covered here for your understanding In-depth coverage of these topics is available in related SQL Server and Microsoft Visual Studio® courses After completing this module, you will be able to:
! Describe how SQL Server 2000 uses XML
! Describe how to implement XML support in SQL Server 2000
! Write basic XML queries against SQL Server 2000 by using Hypertext Transfer Protocol (HTTP)
! Use a basic XML template against SQL Server 2000 to retrieve data
! Insert data into SQL Server 2000 by using XML
! Describe some of the XML features recently added to SQL Server 2000
For in-depth coverage of the implementation of XML in
SQL Server 2000, see Course 2091A, Building XML-Enabled Applications Using Microsoft SQL Server 2000
In this module, you will use SQL Query Analyzer to connect to the Northwind
database To do this, you need the SQL password According to the Manual
Setup Guide, the SQL password is set to 2500
Introduction
Objectives
Important
Trang 10Lesson: XML Support in SQL Server 2000
***************************** ILLEGAL FOR NON - TRAINER USE ******************************
While developing SQL Server 2000, Microsoft determined that the use of XML for Internet-based work was a major requirement This lesson describes the XML support incorporated in the product Just as XML technologies are changing rapidly, so too are the XML technologies in SQL Server
The normal development cycle of three to four years is too long, so interim releases of new XML support in SQL Server are being provided through add-in features You will learn about some of these in this lesson
After completing this lesson, you will be able to:
! Describe key XML features supported in SQL Server 2000
! Describe the architectural features providing XML support in SQL Server 2000
! Identify and describe features added to SQL Server 2000 for XML support
! Explain the range of ways in which SQL Server 2000 provides support for XML in general and for Microsoft NET in particular
Introduction
Lesson objectives
Trang 11XML Features in SQL Server 2000
" FOR XML clause
" OPENXML rowset provider
***************************** ILLEGAL FOR NON - TRAINER USE ******************************
One of the major benefits of combining SQL Server relational data and XML data is that it enables you to easily translate hierarchical data into relational data and vice versa To achieve this, SQL Server relies on several technologies Some are provided with the XML for SQL Server 2000 add-in, and others are the result of SQL Server interoperating with other NET Enterprise Server products
SQL Server interoperates with Internet Information Services (IIS) to process queries by using HTTP Such queries are encoded in Uniform Resource Locator (URL) strings
This table presents some examples of HTTP queries
HTTP query type Example
Direct query to SQL Server
http://bandicoot/nwind?sql=SELECT+*+FROM +Employees+FOR+XML+AUTO&root=root Query that references an
XML schema
http://bandicoot/nwind?template=
sql"><sql:query>SELECT+*+FROM+Employees+FOR+XML+AUTO</sql:query></ROOT>
<ROOT+xmlns:sql="urn:schemas-microsoft-com:xml-Query that references a template file
http://bandicoot/nwind/MyTemplates/mytemplate.xml
Query that references an XSD schema and includes XPath
http://bandicoot/nwind/MySchemas/myschema.xml /Employee[@EmployeeID="2"]
Query that references a database object directly
http://bandicoot/nwind/MyObjects/XpathQuery
Introduction
HTTP access
Examples
Trang 12An XML View allows a query to be processed by using an XML-Data Reduced (XDR) schema An XML View can be queried by using XML Path Language (XPath) This is analogous to using the CREATE VIEW statement in SQL
By using XPath and XSD schemas, which enable you to map database information, you can directly query the database This approach has an important security advantage over allowing URL queries Template files enhance security by hiding details of the database schema from the end user Normally, SQL queries return data in rowset format An SQL query that uses the FOR XML clause returns data in XML format You can further qualify the FOR XML clause by using the RAW, AUTO, or EXPLICIT modes
You can also insert data into the database directly from XML by using the
special stored procedure sp_xml_preparedocument and the OPENXML
rowset provider
To provide the enhanced capabilities for XML support, the Microsoft OLE DB Provider for SQL Server (SQLOLEDB) has new properties that enable you to handle streams with XML data
XML Views
XSD and XPath querying
Read/write XML data
Enhanced SQLOLEDB
Trang 13SQL Server XML Architecture
SQL Database Northwind
IIS and ISAPI SQL Server 2000
Schemas Templates
SQLOLEB
***************************** ILLEGAL FOR NON - TRAINER USE ******************************
To provide XML support in SQL Server 2000, many additions were made to the architecture of SQL Server Enhancements were made to the Microsoft Web server, Internet Information Server (IIS) By combining with IIS technology, Internet Server Application Programming Interface (ISAPI), SQLOLEDB, and Sqlxml.dll, SQL Server can work with XML in an efficient and powerful manner to render queries, insert data, and manipulate database objects
Analysis Server mines data It is an integral part of SQL Server 2000 and provides XML support Analysis Server uses Predictive Model Markup Language (PMML), an XML-based method that is used to analyze data You can use the Microsoft XML for Analysis Provider to process XML analysis queries You implement this by using the Microsoft XML for Analysis Provider software development kit (SDK)
For recent information on the Microsoft XML for Analysis Provider, see Connection Pooling with Microsoft SQL Server 2000 Analysis Services at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsql2k/ html/sql2k_connpooling.asp?frame=true
SQL Server relies on enhancements to IIS to provide XML support In this architecture, most often a Web browser serves as the client The middle tier is handled by IIS IIS connects with SQL Server by using an ISAPI extension through Sqlisapi.dll Data passed from the URL over HTTP to IIS is processed through these mechanisms to Sqlxml.dll through the SQLOLEDB provider The SQLOLEDB provider passes XML commands to Sqlxml.dll, which converts schema and XPath information into SQL commands that SQL Server can process SQL Server also processes the FOR XML clause and the
OPENXML rowset provider so that it can communicate with IIS
Introduction
Note
Architectural features
Trang 14XML for SQL Server 2000
Requires MSXML 3.0 Requires MSXML 3.0
Enhancements to schemas, templates, HTTP and XPath queries Template caching
.NET Framework support – SQLXML Managed Classes and DiffGrams IsXML
Enhanced Dbobject query capability Dbobject queries formalized
An upgraded SQLOLEDB provider Sql:datatype
XML rowset formatting on the client Bulk Load
XML Views with XSD annotated schemas
Updategrams
Features of XML for SQL Server 2000 Features of Web Release 1
***************************** ILLEGAL FOR NON - TRAINER USE ******************************
Since the release of SQL Server 2000, Microsoft has produced significant enhancements to the product to enable richer integration They have used this approach to shorten the product delivery cycle, because the next version of SQL Server is not due for release until 2002 or later
There have been two versions of an add-in named XML for SQL Server 2000 The slide lists the product enhancements incorporated in XML for
SQL Server 2000 These enhancements add to the functionality of SQL Server 2000 for handling XML data and querying
Continuing the Web Release strategy, SQLXML 2.0 adds support for XSD mapping schemas, Client-Side XML functionality, a new SQLXML OLEDB provider, a tool to convert XDR mapping schemas to XSD, and significant performance improvements SQL Server 2000 users can use client-side XML functionality to move XML processing to the middle tier for better scalability
or to wrap SQL Server Stored Procedures with the Transact-SQL FOR XML clause
SQLXML 2.0 also introduces a set of SQLXML Managed Classes that allows NET developers to access SQLXML functionality
There is extensive documentation with XML for SQL Server 2000 This documentation supplements the SQL Server Books Online material on XML support If you install XML for SQL Server 2000, it is particularly important to read the additional documentation, because it changes some of the original behavior of XML support in SQL Server 2000
Introduction
Key features
Documentation
Trang 15Practice: Using SQL Server XML Documentation
Books Online, search for particular topics, and review the documentation on XML support in SQL Server 2000
***************************** ILLEGAL FOR NON - TRAINER USE ******************************
There is extensive documentation in SQL Server 2000 Books Online with which you should become familiar In this practice, you will review this documentation so that you will know where to find it and what it covers
! Gain access to SQL XML documentation
1 Click Start, point to All Programs, click Microsoft SQL Server, and then click Books Online
2 In the left pane, on the Search tab, clear the Match similar words check
box if it is selected
3 In the Type in the word(s) to search for box, type XDR
How many results did you get? Notice the number of Location topics that are in the list
4 In the Type in the word(s) to search for box, type XSD
How many results did you get?
Why were your results so different?