sql server 2000 and xml erik veerman consultant intellinet business intelligence

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

Upload: melvin-bailey

Post on 23-Dec-2015

218 views

Category:

Documents


0 download

TRANSCRIPT

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

SQL Server 2000SQL Server 2000and XMLand XML

Erik VeermanErik Veerman

ConsultantConsultant

IntellinetIntellinetBusiness IntelligenceBusiness Intelligence

Page 2: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

ObjectivesObjectives

Give an overview on the new XML Give an overview on the new XML capabilities in SQL Server 2000capabilities in SQL Server 2000

Demonstrate rather than presentDemonstrate rather than present Provide base knowledge for…Provide base knowledge for…

XML architecture decisionsXML architecture decisions Research starting pointsResearch starting points Pros and cons of parallel XML Pros and cons of parallel XML

technology implementationstechnology implementations Data interaction leveraging SQL’s Data interaction leveraging SQL’s

XML capabilitiesXML capabilities

Page 3: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

AgendaAgenda

The ability to retrieve and write XML The ability to retrieve and write XML data: data: Retrieve XML data using the SELECT Retrieve XML data using the SELECT

statement and the FOR XML clause.statement and the FOR XML clause. Write XML data using OPENXML Write XML data using OPENXML

rowset provider.rowset provider. The ability to access SQL Server The ability to access SQL Server

using HTTP.using HTTP. IIS ConfigurationIIS Configuration Template QueriesTemplate Queries XSL Style sheetsXSL Style sheets

Page 4: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

AgendaAgenda

Support for XDR schemas/XML Support for XDR schemas/XML ViewsViews XPath queries against these schemas.XPath queries against these schemas.

XML for SQL Web ReleaseXML for SQL Web Release Bulk LoadBulk Load UpdategramUpdategram

ADO programming methods ADO programming methods (Chris Hagen)(Chris Hagen)

XML in use (Chris Hagen)XML in use (Chris Hagen)

Page 5: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

Agenda:Agenda:SQL Server 2000 XML SQL Server 2000 XML

SELECTSELECT

How has SQL Server extended How has SQL Server extended the SELECT paradigm to the SELECT paradigm to support XML?support XML?

Page 6: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

SELECT Statement Syntax:SELECT Statement Syntax:

SELECT … … …SELECT … … …

FOR XML FOR XML { RAW | AUTO | EXPLICIT } { RAW | AUTO | EXPLICIT }

[, XMLDATA][, XMLDATA]

[, ELEMENTS][, ELEMENTS]

[, BINARY Base64][, BINARY Base64]

Page 7: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

Simple XML Query:Simple XML Query:SELECTSELECT oh.CustomerID, oh.OrderId,oh.CustomerID, oh.OrderId,

od.ProductID, od.UnitPrice, od.Quantityod.ProductID, od.UnitPrice, od.Quantity

FROM Orders ohFROM Orders oh

INNER JOIN [Order Details] odINNER JOIN [Order Details] od

ON oh.orderid = od.orderidON oh.orderid = od.orderid

FOR XML {RAW | AUTO}FOR XML {RAW | AUTO}

Page 8: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

FOR XML RAW FormatFOR XML RAW Format

Takes the query result and Takes the query result and transforms each row in the transforms each row in the result set into an XML element result set into an XML element with a generic identifier <row /> with a generic identifier <row /> as the element tag.as the element tag.

Page 9: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

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

Page 10: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

FOR XML EXPLICIT FormatFOR XML EXPLICIT Format

Based on the concept of a Universal Based on the concept of a Universal Table containing all the information Table containing all the information about the resulting XML tree.about the resulting XML tree.

Contains Tag and Parent meta-dataContains Tag and Parent meta-data Tag: Tag number of current elementTag: Tag number of current element Parent: Tag number of parent elementParent: Tag number of parent element

Column names are XML Generic Column names are XML Generic identifiers.identifiers. Identifier!TagNumber!AttributeNameIdentifier!TagNumber!AttributeName

Page 11: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

EXPLICIT Sample QueryEXPLICIT Sample QuerySELECT 1 AS Tag, NULL AS Parent,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 ALLUNION ALL

SELECT 2, 1,SELECT 2, 1,

oh.CustomerID, oh.OrderId, od.ProductID, od.UnitPrice, od.Quantityoh.CustomerID, oh.OrderId, od.ProductID, od.UnitPrice, od.Quantity

FROM Orders oh INNER JOIN [Order Details] odFROM Orders oh INNER JOIN [Order Details] od

ON oh.orderid = od.orderid WHERE CustomerId = ‘ANTON’ON oh.orderid = od.orderid WHERE CustomerId = ‘ANTON’

ORDER BYORDER BY

[Order!1!CustomerID], [Order!1!OrderId], [OrderDetail!2!ProductId][Order!1!CustomerID], [Order!1!OrderId], [OrderDetail!2!ProductId]

FOR XML EXPLICITFOR XML EXPLICIT

Page 12: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

SELECT XML FormatsSELECT XML Formats

DEMODEMO

Page 13: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

Agenda:Agenda:SQL Server 2000 SQL Server 2000

OpenXMLOpenXMLAllows one to parse and utilize Allows one to parse and utilize an XML documentan XML document

Page 14: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

OpenXML ProcessOpenXML Process

Input an XML documentInput an XML document Process an internal representationProcess an internal representation

exec sp_xml_preparedocumentexec sp_xml_preparedocument Parse the XML documentParse the XML document

OpenXML Rowset functionOpenXML Rowset function Remove internal representation Remove internal representation

from memoryfrom memory EXEC sp_xml_removedocumentEXEC sp_xml_removedocument

Page 15: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

OpenXML ProcessOpenXML Process

Page 16: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

OpenXML SyntaxOpenXML Syntax

OPENXML(idoc int [in], OPENXML(idoc int [in], rowpattern nvarchar[in], rowpattern nvarchar[in], [flags byte[in]])[flags byte[in]])

[WITH (SchemaDeclaration [WITH (SchemaDeclaration | TableName)]| TableName)]

Page 17: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

OpenXML ProcessOpenXML Process

DEMODEMO

Page 18: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

Agenda:Agenda:SQL Server 2000 IIS SQL Server 2000 IIS

IntegrationIntegration

How does one use IIS for How does one use IIS for retrieving XML data.retrieving XML data.

Page 19: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

Using IIS, the process.Using IIS, the process.

Configure an IIS Virtual RootConfigure an IIS Virtual Root Define template queriesDefine template queries Define style sheetsDefine style sheets Make HTTP requestMake HTTP request

Page 20: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

Configure an IIS Virtual Configure an IIS Virtual RootRoot

DEMODEMO

Page 21: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

HTTP Access to DataHTTP Access to Data

URL QueryURL Query http://sqlserver/vroot?parametershttp://sqlserver/vroot?parameters

ParametersParameters Sql = SELECT+*+FROM+Sku+FOR+ Sql = SELECT+*+FROM+Sku+FOR+

XML+RAWXML+RAW Encoding = UTF-8Encoding = UTF-8 Root = rootRoot = root

Page 22: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

HTTP Access to DataHTTP Access to Data

Direct QueryDirect Query Good for a single select of a single Good for a single select of a single

columncolumn Value is returned in native format, not Value is returned in native format, not

XMLXML Enables direct retrieval of objects like Enables direct retrieval of objects like

images, OLE objects, etc.images, OLE objects, etc. http://sqlserver/vroot/dbobject/xpathhttp://sqlserver/vroot/dbobject/xpath

Page 23: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

What are Template Queries?What are Template Queries?

These are XML documents that These are XML documents that define queriesdefine queries

Can be bound directly to Style Can be bound directly to Style SheetsSheets

Called by referencing the XML Called by referencing the XML document in the URLdocument in the URL

Page 24: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

What are Template Queries?What are Template Queries?

TemplateTemplate http://sqlserver/vroot/vname?paramshttp://sqlserver/vroot/vname?params Vname is a complete path to the Vname is a complete path to the

template XML filetemplate XML file Parameters may be xsl, encoding, or Parameters may be xsl, encoding, or

contenttype; or user defined.contenttype; or user defined. Provides an easy way to perform Provides an easy way to perform

complex queries with little network complex queries with little network traffictraffic

Page 25: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

Why use Template Queries?Why use Template Queries?

Can use dynamic SQL but no Can use dynamic SQL but no restrictions on what is executedrestrictions on what is executed

Automatic formatting of the XML Automatic formatting of the XML header informationheader information

Templates simplify the HTTP Templates simplify the HTTP requestrequest

Templates have better support Templates have better support parametersparameters

Page 26: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

Define and Use StyleSheetsDefine and Use StyleSheets

Can be added to the URLCan be added to the URL XSL=stylesheet.xslXSL=stylesheet.xsl ContentType = text/htmlContentType = text/html

Can be defined in the TemplateCan be defined in the Template

Page 27: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

What does a template What does a template query look like and how is query look like and how is

it run?it run?

DEMODEMO

Page 28: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

Agenda:Agenda:XML XDR SchemaXML XDR Schema

XML Views | Update gramXML Views | Update gram

Mapping relational data through Mapping relational data through an XML schemaan XML schema

Page 29: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

What is an XML View?What is an XML View? Defines an XML-formatted view on Defines an XML-formatted view on

the databasethe database Annotations specify the XML to Annotations specify the XML to

relational database mapping for relational database mapping for column values and relationshipscolumn values and relationships

Uses Xpath to query the XML ViewUses Xpath to query the XML View

Page 30: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

How to use XML ViewsHow to use XML Views http://server/vroot/vname/xpath?http://server/vroot/vname/xpath?

parametersparameters Vname is a direct reference to the Vname is a direct reference to the

schema fileschema file Xpath is the xpath queryXpath is the xpath query Parameters may be xsl, encoding, Parameters may be xsl, encoding,

contenttype, or user definedcontenttype, or user defined

Page 31: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

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

DEMODEMO

Page 32: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

XML for SQL Web ReleaseXML for SQL Web Release

XML for SQL Web Release 1XML for SQL Web Release 1 UpdateGramsUpdateGrams Bulk Load XML supportBulk Load XML support

XML for SQL Web Release 2 XML for SQL Web Release 2 (July 2001)(July 2001) XML Views with XSDXML Views with XSD Support for DiffGramsSupport for DiffGrams Client Side XML formattingClient Side XML formatting

Page 33: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

Update gramUpdate gram

Schema mapping, Update gram syntaxSchema mapping, Update gram syntax Inserts, Updates, DeletesInserts, Updates, Deletes Using <Before> and <After> blocksUsing <Before> and <After> blocks Passing ParametersPassing Parameters

Page 34: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

Writing Data withWriting Data withUpdate GramsUpdate Grams

Update grams (example)Update grams (example)<ROOT xmlns:updg="urn:schemas-microsoft-com:xml-<ROOT xmlns:updg="urn:schemas-microsoft-com:xml-

updategram">updategram"><updg:sync mapping-schema="SampleSchema.xml" ><updg:sync mapping-schema="SampleSchema.xml" ><updg:before><updg:before></updg:before></updg:before><updg:after><updg:after> <Customer CustID="AAAAA" Company="Bottom-<Customer CustID="AAAAA" Company="Bottom-

Dollar Markets" />Dollar Markets" /> </updg:after></updg:after></updg:sync></updg:sync></ROOT></ROOT>

Page 35: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

Miscellaneous Data Retreival:Miscellaneous Data Retreival:OLAP dataOLAP data

sp_makewebsqlsp_makewebsql

DEMODEMO

Page 36: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

Agenda:Agenda:ADO Programming ADO Programming

Methods for SQL Server Methods for SQL Server 2000 XML2000 XML

How does one write How does one write components utilizing the new components utilizing the new SELECT FOR XML and IIS?SELECT FOR XML and IIS?

Page 37: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

Utilize ADO FunctionalityUtilize ADO Functionality

Calls made through ADO CommandCalls made through ADO Command Uses ADO Stream ObjectUses ADO Stream Object Requires ADO 2.6Requires ADO 2.6

Stream Object defined as a property of Stream Object defined as a property of the Command Objectthe Command Object

XML Data placed in the Stream XML Data placed in the Stream ObjectObject Obtained using ReadTextObtained using ReadText

Page 38: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

ADO supports XMLADO supports XML

Recordsets can be persisted to XMLRecordsets can be persisted to XML FileFile Stream ObjectStream Object DOM IntegrationDOM Integration IIS5 Response ObjectIIS5 Response Object

Also support for ADTGAlso support for ADTG Advanced Data Table Gram formatAdvanced Data Table Gram format

Support Hierarchical RecordsetsSupport Hierarchical Recordsets

Page 39: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

ADO XML Stream SupportADO XML Stream Support

Can persist directly to an ADO Can persist directly to an ADO Stream ObjectStream Object

XML extracted using Stream XML extracted using Stream ReadTextReadText

XML data can then be utilized in XML data can then be utilized in memorymemory Pass XML back to clientPass XML back to client Transform to HTML using XSLTransform to HTML using XSL

Page 40: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

ADO and DOM IntegrationADO and DOM Integration

Can persist XML directly into the Can persist XML directly into the XML DOM DocumentXML DOM Document

Recordset.Save Recordset.Save MSXML.DOMDocument, MSXML.DOMDocument, adPersistXMLadPersistXML

Can perform direct XSL transform Can perform direct XSL transform for HTML based componentsfor HTML based components

Page 41: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

ADO and IIS5 ResponseADO and IIS5 Response

Response Object exposes and Response Object exposes and IStream InterfaceIStream Interface

Recordset.Save Response, Recordset.Save Response, adPersistXMLadPersistXML

Displays XML in browserDisplays XML in browser Avoids expensive disk operationsAvoids expensive disk operations

Page 42: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

ADO XML ProgrammingADO XML Programming

DEMODEMO

Page 43: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

For further InformationFor further Information

XML websiteXML websitehttp://msdn.microsoft.com/xmlhttp://msdn.microsoft.com/xml

SQL Server 2000 and IISSQL Server 2000 and IIShttp://msdn.microsoft.com/msdnmag/isshttp://msdn.microsoft.com/msdnmag/issues/0300/sql/sql.aspues/0300/sql/sql.asp

SQL Server 2000 SQL Server 2000 http://www.microsoft.com/http://www.microsoft.com/sqlsql

ADO ADO http://www.microsoft.com/adohttp://www.microsoft.com/ado

Page 44: SQL Server 2000 and XML Erik Veerman Consultant Intellinet Business Intelligence

Feedback / Questions ?Feedback / Questions ?