Presentation is loading. Please wait.

Presentation is loading. Please wait.

SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence.

Similar presentations


Presentation on theme: "SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence."— Presentation transcript:

1 SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

2 Objectives Give an overview on the new XML capabilities in SQL Server 2000 Give an overview on the new XML capabilities in SQL Server 2000 Demonstrate rather than present Demonstrate rather than present Provide base knowledge for… Provide base knowledge for…  XML architecture decisions  Research starting points  Pros and cons of parallel XML technology implementations  Data interaction leveraging SQL’s XML capabilities

3 Agenda The ability to retrieve and write XML data: The ability to retrieve and write XML data:  Retrieve XML data using the SELECT statement and the FOR XML clause.  Write XML data using OPENXML rowset provider. The ability to access SQL Server using HTTP. The ability to access SQL Server using HTTP.  IIS Configuration  Template Queries  XSL Style sheets

4 Agenda Support for XDR schemas/XML Views Support for XDR schemas/XML Views  XPath queries against these schemas. XML for SQL Web Release XML for SQL Web Release  Bulk Load  Updategram ADO programming methods (Chris Hagen) ADO programming methods (Chris Hagen) XML in use (Chris Hagen) XML in use (Chris Hagen)

5 Agenda: SQL Server 2000 XML SELECT How has SQL Server extended the SELECT paradigm to support XML?

6 SELECT Statement Syntax: SELECT … … … FOR XML { RAW | AUTO | EXPLICIT } [, XMLDATA] [, ELEMENTS] [, BINARY Base64]

7 Simple XML Query: SELECToh.CustomerID, oh.OrderId, od.ProductID, od.UnitPrice, od.Quantity FROM Orders oh INNER JOIN [Order Details] od ON oh.orderid = od.orderid FOR XML {RAW | AUTO}

8 FOR XML RAW Format Takes the query result and transforms each row in the result set into an XML element with a generic identifier as the element tag.

9 FOR XML AUTO Format Returns query results in a simple, nested XML tree. Each table in the FROM clause for which at least one column is listed in the SELECT clause is represented as an XML element. The columns listed in the SELECT clause are mapped to the appropriate element attributes.

10 FOR XML EXPLICIT Format Based on the concept of a Universal Table containing all the information about the resulting XML tree. Based on the concept of a Universal Table containing all the information about the resulting XML tree. Contains Tag and Parent meta-data Contains Tag and Parent meta-data  Tag: Tag number of current element  Parent: Tag number of parent element Column names are XML Generic identifiers. Column names are XML Generic identifiers.  Identifier!TagNumber!AttributeName

11 EXPLICIT Sample Query SELECT 1 AS Tag, NULL AS Parent, oh.CustomerID [Order!1!CustomerID], oh.OrderId [Order!1!OrderId], oh.CustomerID [Order!1!CustomerID], oh.OrderId [Order!1!OrderId], NULL [OrderDetail!2!ProductId], NULL [OrderDetail!2!UnitPrice], NULL [OrderDetail!2!ProductId], NULL [OrderDetail!2!UnitPrice], NULL [OrderDetail!2!Quantity] NULL [OrderDetail!2!Quantity] FROM Orders oh WHERE oh.CustomerId = ‘ANTON’ FROM Orders oh WHERE oh.CustomerId = ‘ANTON’ UNION ALL SELECT 2, 1, oh.CustomerID, oh.OrderId, od.ProductID, od.UnitPrice, od.Quantity oh.CustomerID, oh.OrderId, od.ProductID, od.UnitPrice, od.Quantity FROM Orders oh INNER JOIN [Order Details] od FROM Orders oh INNER JOIN [Order Details] od ON oh.orderid = od.orderid WHERE CustomerId = ‘ANTON’ ON oh.orderid = od.orderid WHERE CustomerId = ‘ANTON’ ORDER BY [Order!1!CustomerID], [Order!1!OrderId], [OrderDetail!2!ProductId] [Order!1!CustomerID], [Order!1!OrderId], [OrderDetail!2!ProductId] FOR XML EXPLICIT

12 SELECT XML Formats DEMO

13 Agenda: SQL Server 2000 OpenXML Allows one to parse and utilize an XML document

14 OpenXML Process Input an XML document Input an XML document Process an internal representation Process an internal representation  exec sp_xml_preparedocument Parse the XML document Parse the XML document  OpenXML Rowset function Remove internal representation from memory Remove internal representation from memory  EXEC sp_xml_removedocument

15 OpenXML Process

16 OpenXML Syntax OPENXML(idoc int [in], rowpattern nvarchar[in], [flags byte[in]]) [WITH (SchemaDeclaration | TableName)]

17 OpenXML Process DEMO

18 Agenda: SQL Server 2000 IIS Integration How does one use IIS for retrieving XML data.

19 Using IIS, the process. Configure an IIS Virtual Root Configure an IIS Virtual Root Define template queries Define template queries Define style sheets Define style sheets Make HTTP request Make HTTP request

20 Configure an IIS Virtual Root DEMO

21 HTTP Access to Data URL Query URL Query  http://sqlserver/vroot?parameters Parameters Parameters  Sql = SELECT+*+FROM+Sku+FOR+ XML+RAW  Encoding = UTF-8  Root = root

22 HTTP Access to Data Direct Query Direct Query  Good for a single select of a single column  Value is returned in native format, not XML  Enables direct retrieval of objects like images, OLE objects, etc. http://sqlserver/vroot/dbobject/xpath http://sqlserver/vroot/dbobject/xpath

23 What are Template Queries? These are XML documents that define queries These are XML documents that define queries Can be bound directly to Style Sheets Can be bound directly to Style Sheets Called by referencing the XML document in the URL Called by referencing the XML document in the URL

24 What are Template Queries? Template Template  http://sqlserver/vroot/vname?params  Vname is a complete path to the template XML file  Parameters may be xsl, encoding, or contenttype; or user defined.  Provides an easy way to perform complex queries with little network traffic

25 Why use Template Queries? Can use dynamic SQL but no restrictions on what is executed Can use dynamic SQL but no restrictions on what is executed Automatic formatting of the XML header information Automatic formatting of the XML header information Templates simplify the HTTP request Templates simplify the HTTP request Templates have better support parameters Templates have better support parameters

26 Define and Use StyleSheets Can be added to the URL Can be added to the URL  XSL=stylesheet.xsl  ContentType = text/html Can be defined in the Template Can be defined in the Template

27 What does a template query look like and how is it run? DEMO

28 Agenda: XML XDR Schema XML Views | Update gram Mapping relational data through an XML schema

29 What is an XML View? Defines an XML-formatted view on the database Defines an XML-formatted view on the database Annotations specify the XML to relational database mapping for column values and relationships Annotations specify the XML to relational database mapping for column values and relationships Uses Xpath to query the XML View Uses Xpath to query the XML View

30 How to use XML Views http://server/vroot/vname/xpath?par ameters http://server/vroot/vname/xpath?par ameters Vname is a direct reference to the schema file Vname is a direct reference to the schema file Xpath is the xpath query Xpath is the xpath query Parameters may be xsl, encoding, contenttype, or user defined Parameters may be xsl, encoding, contenttype, or user defined

31 How do I select data from an XML View? DEMO

32 XML for SQL Web Release XML for SQL Web Release 1 XML for SQL Web Release 1  UpdateGrams  Bulk Load XML support XML for SQL Web Release 2 (July 2001) XML for SQL Web Release 2 (July 2001)  XML Views with XSD  Support for DiffGrams  Client Side XML formatting

33 Update gram  Schema mapping, Update gram syntax  Inserts, Updates, Deletes  Using and blocks  Passing Parameters

34 Writing Data with Update Grams Update grams (example) Update grams (example) <updg:before></updg:before><updg:after> </updg:sync></ROOT>

35 Miscellaneous Data Retreival: OLAP data sp_makewebsql DEMO

36 Agenda: ADO Programming Methods for SQL Server 2000 XML How does one write components utilizing the new SELECT FOR XML and IIS?

37 Utilize ADO Functionality Calls made through ADO Command Calls made through ADO Command Uses ADO Stream Object Uses ADO Stream Object Requires ADO 2.6 Requires ADO 2.6  Stream Object defined as a property of the Command Object XML Data placed in the Stream Object XML Data placed in the Stream Object  Obtained using ReadText

38 ADO supports XML Recordsets can be persisted to XML Recordsets can be persisted to XML  File  Stream Object  DOM Integration  IIS5 Response Object Also support for ADTG Also support for ADTG  Advanced Data Table Gram format Support Hierarchical Recordsets Support Hierarchical Recordsets

39 ADO XML Stream Support Can persist directly to an ADO Stream Object Can persist directly to an ADO Stream Object XML extracted using Stream ReadText XML extracted using Stream ReadText XML data can then be utilized in memory XML data can then be utilized in memory  Pass XML back to client  Transform to HTML using XSL

40 ADO and DOM Integration Can persist XML directly into the XML DOM Document Can persist XML directly into the XML DOM Document Recordset.Save MSXML.DOMDocument, adPersistXML Recordset.Save MSXML.DOMDocument, adPersistXML Can perform direct XSL transform for HTML based components Can perform direct XSL transform for HTML based components

41 ADO and IIS5 Response Response Object exposes and IStream Interface Response Object exposes and IStream Interface Recordset.Save Response, adPersistXML Recordset.Save Response, adPersistXML Displays XML in browser Displays XML in browser Avoids expensive disk operations Avoids expensive disk operations

42 ADO XML Programming DEMO

43 For further Information XML website XML website http://msdn.microsoft.com/xml SQL Server 2000 and IIS SQL Server 2000 and IIS http://msdn.microsoft.com/msdnmag/iss ues/0300/sql/sql.asp http://msdn.microsoft.com/msdnmag/iss ues/0300/sql/sql.asp SQL Server 2000 http://www.microsoft.com/sql SQL Server 2000 http://www.microsoft.com/sql http://www.microsoft.com/sql ADO http://www.microsoft.com/ado ADO http://www.microsoft.com/ado http://www.microsoft.com/ado

44 Feedback / Questions ?


Download ppt "SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence."

Similar presentations


Ads by Google