2/23/05 CS-561 - Advanced Databases 1 XML Support in SQL Server 2000 Sriram Krishnan Kevin Menard.

Slides:



Advertisements
Similar presentations
XML-XSL Introduction SHIJU RAJAN SHIJU RAJAN Outline Brief Overview Brief Overview What is XML? What is XML? Well Formed XML Well Formed XML Tag Name.
Advertisements

Chungnam National University DataBase System Lab
3rd Annual Plex/2E Worldwide Users Conference Page based on Title Slide from Slide Layout palette. Design is cacorp Title text for Title or Divider.
1 Senn, Information Technology, 3 rd Edition © 2004 Pearson Prentice Hall James A. Senns Information Technology, 3 rd Edition Chapter 7 Enterprise Databases.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to XHTML Programming the World Wide Web Fourth edition.
Advanced SQL Topics Edward Wu.
Chapter 1: The Database Environment
Copyright © 2003 Pearson Education, Inc. Slide 7-1 Created by Cheryl M. Hughes, Harvard University Extension School Cambridge, MA The Web Wizards Guide.
Copyright © 2003 Pearson Education, Inc. Slide 8-1 Created by Cheryl M. Hughes, Harvard University Extension School Cambridge, MA The Web Wizards Guide.
Copyright © 2003 Pearson Education, Inc. Slide 3-1 Created by Cheryl M. Hughes The Web Wizards Guide to XML by Cheryl M. Hughes.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 9 Using Perl for CGI Programming.
Copyright © 2003 Pearson Education, Inc. Slide 7-1 Created by Cheryl M. Hughes The Web Wizards Guide to XML by Cheryl M. Hughes.
Chapter 1 The Study of Body Function Image PowerPoint
1 Copyright © 2013 Elsevier Inc. All rights reserved. Appendix 01.
17. Data Access ADO.Net Architecture New Features of ADO.NET
4 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: Servlets.
9 Copyright © 2005, Oracle. All rights reserved. Modularizing JavaServer Pages Development with Tags.
8 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: JavaServer Pages.
Introduction to HTML, XHTML, and CSS
Overview Environment for Internet database connectivity
Server Access The REST of the Story David Cleary
Information Systems Today: Managing in the Digital World
1 The phone in the cloud Utilizing resources hosted anywhere Claes Nilsson.
Campaign Overview Mailers Mailing Lists
1 Web-Enabled Decision Support Systems Access Introduction: Touring Access Prof. Name Position (123) University Name.
Creating Tables in a Web Site
Chapter Information Systems Database Management.
Access Tables 1. Creating a Table Design View Define each field and its properties Data Sheet View Essentially spreadsheet Enter fields You must go to.
1 What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language A scripting language is a lightweight.
Integrating XML in Business Ken Spencer Vice President 32X Corporation
15. Oktober Oktober Oktober 2012.
The World Wide Web. 2 The Web is an infrastructure of distributed information combined with software that uses networks as a vehicle to exchange that.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 23 – ASP.NET Outline 23.1 Introduction 23.2.NET Overview NET Framework ASP (Active.
©2007 First Wave Consulting, LLC A better way to do business. Period This is definitely NOT your father’s standard operating procedure.
4 Oracle Data Integrator First Project – Simple Transformations: One source, one target 3-1.
Database System Concepts and Architecture
31242/32549 Advanced Internet Programming Advanced Java Programming
© 2012 National Heart Foundation of Australia. Slide 2.
Chapter 9: The Client/Server Database Environment
Dr. Alexandra I. Cristea XHTML.
25 seconds left…...
Chapter 10: The Traditional Approach to Design
Systems Analysis and Design in a Changing World, Fifth Edition
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
Chapter 11 Creating Framed Layouts Principles of Web Design, 4 th Edition.
14 Databases Foundations of Computer Science ã Cengage Learning.
Chapter 13 The Data Warehouse
Chapter 16 The World Wide Web Nell Dale John Lewis.
Inside Data Access with SQLXML: Architecture Guide Rolandas Gricius MCT, MCSE, MCSD Adapted From.
Fundamentals, Design, and Implementation, 9/e Chapter 12 ODBC, OLE DB, ADO, and ASP.
SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence.
DAT304 Leveraging XML and HTTP with Sql Server Irwin Dolobowsky Program Manager Webdata Group.
Integrating XML with Microsoft SQL Server ©NIITeXtensible Markup Language/Lesson 9/Slide 1 of 31 Objectives In this lesson, you will learn to: * Generate.
4-1 INTERNET DATABASE CONNECTOR Colorado Technical University IT420 Tim Peterson.
Chapter 27 The World Wide Web and XML. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.27-2 Topics in this Chapter The Web and the Internet.
5/24/01 Leveraging SQL Server 2000 in ColdFusion Applications December 9, 2003 Chris Lomvardias SRA International
Module 18 Querying XML Data in SQL Server® 2008 R2.
Retrieving XML Data from SQL server.  Using the FOR XML Clause to Retrieve Data Retrieving Data in XML Format How SQL Server Generates XML Using the.
Chapter 27 The World Wide Web and XML. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.27-2 Topics in this Chapter The Web and the Internet.
Chapter 14 1 Chapter 14 Storing and Retrieving XML in SQL Server 2000 November 6, 2001 Sook-Kyo Kwon.
SQLXML XML Technology For SQL Server Brian Moore Developer and Platform Strategy Group Microsoft Corporation.
Module 3: Using XML. Overview Retrieving XML by Using FOR XML Shredding XML by Using OPENXML Introducing XQuery Using the xml Data Type.
DAT 405 Extreme SqlXml Irwin Dolobowsky Program Manager – SqlXml Microsoft Corporation.
Dev399 SQLXML: XML Views and Relational Data Irwin Dolobowsky Program Manager Webdata Group Microsoft Corporation.
Chapter 29. Copyright 2003, Paradigm Publishing Inc. CHAPTER 29 BACKNEXTEND 29-2 LINKS TO OBJECTIVES Attach an XML Schema Attach an XML Schema Load XML.
XML and SQL Server Better friends than you thought Matt Hartman.
Generating XML Data from a Database Eugenia Fernandez IUPUI.
DAT 400 Inside Data Access with SQLXML: Architecture Guide Alexander Vaschillo Lead Program Manager WebData XML Group Microsoft Corporation.
Jim Fawcett CSE686 – Internet Programming Spring 2014
XML: Extensible Markup Language
Presentation transcript:

2/23/05 CS Advanced Databases 1 XML Support in SQL Server 2000 Sriram Krishnan Kevin Menard

2/23/05 2CS Advanced Databases SQL Server - XML SQL Server 2000 is an XML-enabled DBMS: SQL Server 2000 is an XML-enabled DBMS: It can read and write XML data It can read and write XML data It can return data from databases in XML format It can return data from databases in XML format It can read and update data stored in XML documents It can read and update data stored in XML documents

2/23/05 3CS Advanced Databases SQL Server's XML Features FOR XML FOR XML An extension to SELECT - allows result sets as XML An extension to SELECT - allows result sets as XML OpenXML OpenXML Allows reading and writing of data in XML documents Allows reading and writing of data in XML documents XPath queries XPath queries Allows SQL Server databases to be queried using XPath syntax Allows SQL Server databases to be queried using XPath syntax Schemas Supports XDR mapping schema and XPath queries against them Updategrams XML templates for data modifications XML Bulk Load A high-speed facility for loading XML data into a SQL Server

2/23/05 4CS Advanced Databases SELECT … FOR XML FOR XML causes SELECT to return query results as an XML stream FOR XML causes SELECT to return query results as an XML stream Three formats: RAW, AUTO, or EXPLICIT Three formats: RAW, AUTO, or EXPLICIT SELECT column list FROM table list WHERE filter criteria FOR XML RAW | AUTO | EXPLICIT [, XMLDATA] [, ELEMENTS] [, BINARY BASE64] SELECT column list FROM table list WHERE filter criteria FOR XML RAW | AUTO | EXPLICIT [, XMLDATA] [, ELEMENTS] [, BINARY BASE64]

2/23/05 5CS Advanced Databases FOR XML -- Raw Mode SELECT CustomerId, CompanyName FROM Customers FOR XML RAW: SELECT CustomerId, CompanyName FROM Customers FOR XML RAW:XML_F52E2B61-18A1-11d1-B F49916B Columns Attributes Columns Attributes Rows Generic row element Rows Generic row element XML returned is not well-formed XML returned is not well-formed Lacks a root element – must be generated by the client Lacks a root element – must be generated by the client

2/23/05 6CS Advanced Databases FOR XML -- Auto Mode SELECT CustomerId, CompanyName FROM Customers FOR XML AUTO SELECT CustomerId, CompanyName FROM Customers FOR XML AUTOXML_F52E2B61-18A1-11d1-B F49916B Each row in the result set is named after the table or view Each row in the result set is named after the table or view For results with more than one row, this amounts to having more than one top-level (root) element in the fragment, which isn't allowed in XML For results with more than one row, this amounts to having more than one top-level (root) element in the fragment, which isn't allowed in XML The rows from joined tables are nested within one another. The rows from joined tables are nested within one another.

2/23/05 7CS Advanced Databases FOR XML -- Auto Mode (cont.) Example of a JOIN query: Example of a JOIN query: SELECT Customers.CustomerID, CompanyName, OrderId FROM Customers JOIN Orders ON (Customers.CustomerId=Orders.CustomerId) FOR XML AUTO XML_F52E2B61-18A1-11d1-B F49916B </Customers> </Customers> </Customers>

2/23/05 8CS Advanced Databases FOR XML – Explicit Mode More flexible and more complicated than either raw mode or auto mode More flexible and more complicated than either raw mode or auto mode Explicit mode queries define XML documents in terms of a universal table format Explicit mode queries define XML documents in terms of a universal table format A mechanism for describing the format of XML document returned A mechanism for describing the format of XML document returned A universal table is just a SQL Server result set with special column headings that tell the server how to produce an XML document from your data A universal table is just a SQL Server result set with special column headings that tell the server how to produce an XML document from your data Element!Tag!Attribute!Directive Element!Tag!Attribute!Directive

2/23/05 9CS Advanced Databases Universal Table Format Tag Parent Customers!1!CustomerId Customers!1 Orders!2!OrderId Orders!2!OrderDate!element NULL ALFKI Alfreds Futterkiste NULL NULL 2 1 ALFKI NULL T00:00: ALFKI NULL T00:00:00 1 NULL ANATR Ana Trujillo Empare NULL NULL 2 1 ANATR NULL T00:00:00

2/23/05 10CS Advanced Databases Explicit Mode – Complex Query Links the Customers and Orders tables using the CustomerId column Links the Customers and Orders tables using the CustomerId column The Tag and Parent values in the second query link it to the first The Tag and Parent values in the second query link it to the first SELECT 1 AS Tag, NULL AS Parent, CustomerId AS [Customers!1!CustomerId], CompanyName AS [Customers!1], NULL AS [Orders!2!OrderId], NULL AS [Orders!2!OrderDate!element] FROM Customers UNION SELECT 2 AS Tag, 1 AS Parent, CustomerId, NULL, OrderId, OrderDate FROM Orders ORDER BY [Customers!1!CustomerId], [Orders!2!OrderDate!element] FOR XML EXPLICIT XML_F52E2B61-18A1-11d1-B F49916B Alfreds Futterkiste Alfreds Futterkiste <OrderDate> T00:00:00</OrderDate></Orders> <OrderDate> T00:00:00</OrderDate></Orders></Customers> Ana Trujillo Emparedados y helados Ana Trujillo Emparedados y helados <OrderDate> T00:00:00</OrderDate></Orders></Customers>

2/23/05 11CS Advanced Databases OpenXML OpenXML is a built-in Transact-SQL function that can return an XML document as a rowset OpenXML is a built-in Transact-SQL function that can return an XML document as a rowset Syntax: Syntax: OpenXML(hdoc, RowPattern [, Flag] [WITH SchemaDeclaration | TableName] OpenXML(hdoc, RowPattern [, Flag] [WITH SchemaDeclaration | TableName] hdoc = Handle to XML Document hdoc = Handle to XML Document Returned from sp_xml_preparedocument Returned from sp_xml_preparedocument RowPattern = XPath expression that identifies rows RowPattern = XPath expression that identifies rows Flag = Attribute or element-centric column patterns Flag = Attribute or element-centric column patterns WITH = Shredded rowset based upon additional parameters (omission of WITH = edge table view) WITH = Shredded rowset based upon additional parameters (omission of WITH = edge table view)

2/23/05 12CS Advanced Databases OpenXML Example int EXEC output, '<songs> It Was Almost Like a Song It Was Almost Like a Song I See Your Face Before Me I See Your Face Before Me Easy Living Easy Living Sonny Cried Sonny Cried A Nightingale Sang A Nightingale Sang You Didn't Know Me When You Didn't Know Me When </songs>' SELECT * FROM '/songs/artist/song', 2) WITH (artist varchar(30) song varchar(50) 'name') song varchar(50) 'name') EXEC artist song Johnny Hartman It Was Almost Like a Song Johnny Hartman I See Your Face Before Me Johnny Hartman Easy Living Harry Connick Jr. Sonny Cried Harry Connick Jr. A Nightingale Sang, Harry Connick Jr. You Didn't Know Me When

2/23/05 13CS Advanced Databases XML Mapping Schema XML schemas are XML documents that define the type of data that other XML documents may contain XML schemas are XML documents that define the type of data that other XML documents may contain Replacement for DTD Replacement for DTD A mapping schema is a special type of schema that maps data between an XML document and a relational table A mapping schema is a special type of schema that maps data between an XML document and a relational table Can be used to create an XML view of a SQL Server table Can be used to create an XML view of a SQL Server table SQL Server's XML schema support is based on XML-Data Reduced (XDR) SQL Server's XML schema support is based on XML-Data Reduced (XDR) An XML-Data subset that can be used to define schemas An XML-Data subset that can be used to define schemas

2/23/05 14CS Advanced Databases Annotated Mapping Schema An annotated schema is a mapping schema with special annotations (from the XML-SQL namespace) that link elements and attributes with tables and columns An annotated schema is a mapping schema with special annotations (from the XML-SQL namespace) that link elements and attributes with tables and columns Table element (default) Table element (default) Column attribute (default) Column attribute (default) Provides same level of granularity as FOR … XML EXPLICIT, without having to use universal tables Provides same level of granularity as FOR … XML EXPLICIT, without having to use universal tables

2/23/05 15CS Advanced Databases Annotated Mapping Schema (cont.) Example Schema: Example Schema: </ElementType></Schema>

2/23/05 16CS Advanced Databases Querying Using XPath XPath is a tree navigation language defined by W3C XPath is a tree navigation language defined by W3C SQL Server uses XPath to select data from XML views provided by annoted schema SQL Server uses XPath to select data from XML views provided by annoted schema XPath query can be passed via URL or template or via SQLOLEDB provider XPath query can be passed via URL or template or via SQLOLEDB provider

2/23/05 17CS Advanced Databases Updategrams Updategrams provide an XML-based method to update database Updategrams provide an XML-based method to update database Templates with special attributes and elements Templates with special attributes and elements Specify the data to update, how to update it Specify the data to update, how to update it All the execution mechanisms available with templates work equally well with updategrams All the execution mechanisms available with templates work equally well with updategrams POST, save to file and execute via URL, via ADO POST, save to file and execute via URL, via ADO

2/23/05 18CS Advanced Databases Updategrams (cont.) Each updategram: Each updategram: Contains the data changes in the form of before and after elements. Contains the data changes in the form of before and after elements. Before element contains the before image of the data to be changed Before element contains the before image of the data to be changed Row deletions Row deletions Have before image but no after image Have before image but no after image Row Insertions Row Insertions Have an after image but no before image Have an after image but no before image

2/23/05 19CS Advanced Databases Updategrams (cont.) <updg:sync><updg:before> </updg:before><updg:after> </updg:sync></employeeupdate> Updategrams can also be parameterized: Updategrams can also be parameterized:<updg:header> </updg:header>

2/23/05 20CS Advanced Databases Updategrams (cont.) Updategrams can also use XDR mapping schemas: Updategrams can also use XDR mapping schemas: Where the XDR schema is given by: Where the XDR schema is given by:

2/23/05 21CS Advanced Databases XML Bulk Load Updategrams and OpenXML, are not suitable for loading large amounts of data Updategrams and OpenXML, are not suitable for loading large amounts of data SQLXML provides a facility called the XML Bulk Load SQLXML provides a facility called the XML Bulk Load COM object COM object The first step in using the XML Bulk Load is to define a mapping schema that maps the XML data to tables and columns in database The first step in using the XML Bulk Load is to define a mapping schema that maps the XML data to tables and columns in database When the component loads the XML data, it will read it as a stream and use the mapping schema to decide where the data goes in the database When the component loads the XML data, it will read it as a stream and use the mapping schema to decide where the data goes in the database

2/23/05 22CS Advanced Databases XML Bulk Load (cont.) VB Example: VB Example: Set objBulkLoad=CreateObject("SQLXMLBulkLoad.S QLXMLBulkLoad") objBulkLoad.ConnectionString = "provider=SQLOLEDB;data source=SuperServer;database=Northwind;" objBulkLoad.Execute "d:\xml\OrdersSchema.xdr", "d:\xml\OrdersData.xml" Set objBulkLoad = Nothing

2/23/05 23CS Advanced Databases Accessing SQL Server Over HTTP SQL Server's ability to publish data over HTTP is made possible through SQLISAPI with IIS SQL Server's ability to publish data over HTTP is made possible through SQLISAPI with IIS An Internet Server API (ISAPI) extension An Internet Server API (ISAPI) extension SQLISAPI uses SQLOLEDB, SQL Server's native OLE DB provider, to access the database associated with a virtual directory SQLISAPI uses SQLOLEDB, SQL Server's native OLE DB provider, to access the database associated with a virtual directory Configuring a virtual directory allows SQL Server's XML features via HTTP Configuring a virtual directory allows SQL Server's XML features via HTTP

2/23/05 24CS Advanced Databases Accessing SQL Server over HTTP (cont.) Private Intranet Private Intranet Send a SELECT … FOR XML query string in URL Send a SELECT … FOR XML query string in URL Post an XML query template to SQLISAPI Post an XML query template to SQLISAPI Public Internet Public Internet Specify a server-side XML schema Specify a server-side XML schema Specify a server-side XML query template Specify a server-side XML query template

2/23/05 25CS Advanced Databases URL Queries URL queries allow users to specify a complete Transact-SQL query via a URL URL queries allow users to specify a complete Transact-SQL query via a URL +*+FROM+Customers+WHERE+CustomerId='A LFKI'+OR+CustomerId='ANATR'+FOR+XML+A UTO &root=CustomerList +*+FROM+Customers+WHERE+CustomerId='A LFKI'+OR+CustomerId='ANATR'+FOR+XML+A UTO &root=CustomerList The first parameter we pass here is sql The first parameter we pass here is sql The second parameter specifies the name of the root element for the XML document that will be returned The second parameter specifies the name of the root element for the XML document that will be returned

2/23/05 26CS Advanced Databases URL Queries (cont.) URL query can also include the xsl parameter URL query can also include the xsl parameter Translates the XML document that's returned by the query into a different format Translates the XML document that's returned by the query into a different format d,+CompanyName+FROM+Customers+FOR+XML+AUTO&root =CustomerList&xsl=CustomerList.xsl d,+CompanyName+FROM+Customers+FOR+XML+AUTO&root =CustomerList&xsl=CustomerList.xsl panyName+FROM+Customers+FOR+XML+AUTO&root=CustomerLis t&xsl=CustomerList.xsl&contenttype=text/xml panyName+FROM+Customers+FOR+XML+AUTO&root=CustomerLis t&xsl=CustomerList.xsl&contenttype=text/xml

2/23/05 27CS Advanced Databases Executing Stored Procedures via URL Stored Procedure: Stored Procedure: CREATE PROC varchar(80)='%' AS SELECT CustomerId, CompanyName FROM Customers WHERE CustomerId AND CompanyName FOR XML AUTO URL for executing stored procedure: URL for executing stored procedure: merList

2/23/05 28CS Advanced Databases Template Queries Templates are XML documents based on the XML- SQL namespace Templates are XML documents based on the XML- SQL namespace Mechanism for translating a URL into a query that SQL Server can process Mechanism for translating a URL into a query that SQL Server can process Safer and more widely used technique for retrieving data over HTTP Safer and more widely used technique for retrieving data over HTTP End users never see the source code End users never see the source code Templates are stored on the Web server Templates are stored on the Web server Referenced via a virtual name Referenced via a virtual name

2/23/05 29CS Advanced Databases Sample Template <sql:query> SELECT CustomerId, CompanyName FROM Customers FOR XML AUTO </sql:query></CustomerList> Example invocation: Example invocation: Specify a style sheet to apply to a template query: Specify a style sheet to apply to a template query: =Templates/CustomerList3.xsl&contenttype=text/html

2/23/05 30CS Advanced Databases Templates Parameterized Templates Parameterized Templates Permit the user to supply parameters to the query Permit the user to supply parameters to the query % % SELECT CustomerId, CompanyName FROM Customers WHERE CustomerId FOR XML AUTO SELECT CustomerId, CompanyName FROM Customers WHERE CustomerId FOR XML AUTO </CustomerList> Example invocation: Example invocation: ist2.XML? CustomerId=A%25

2/23/05 31CS Advanced Databases Conclusions SQL Server 2000 has a lot of ways to work with XML, suitable for a number of situations SQL Server 2000 has a lot of ways to work with XML, suitable for a number of situations Questions? Questions? References: References: Conrad, Andrew. A Survey of Microsoft SQL Server 2000 XML Features: Microsoft Corporation, 2001 Conrad, Andrew. A Survey of Microsoft SQL Server 2000 XML Features: Microsoft Corporation, us/dnexxml/html/xml asp us/dnexxml/html/xml asp Henderson, Ken. Guru's Guide to SQL Server Architecture and Internals, The (Chapter: Using SQL Server's XML Support) Henderson, Ken. Guru's Guide to SQL Server Architecture and Internals, The (Chapter: Using SQL Server's XML Support) Rys, Michael. Bringing the Internet to Your Database: Using SQL Server 2000 and XML to Build Loosely-Coupled Systems: Microsoft Corporation Rys, Michael. Bringing the Internet to Your Database: Using SQL Server 2000 and XML to Build Loosely-Coupled Systems: Microsoft Corporation