Download
sql server 2000 and xml n.
Skip this Video
Loading SlideShow in 5 Seconds..
SQL Server 2000 and XML PowerPoint Presentation
Download Presentation
SQL Server 2000 and XML

SQL Server 2000 and XML

324 Vues Download Presentation
Télécharger la présentation

SQL Server 2000 and XML

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. SQL Server 2000and XML Erik Veerman Consultant IntellinetBusiness Intelligence

  2. Objectives • Give an overview on the new XML capabilities in SQL Server 2000 • Demonstrate rather than present • 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: • 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. • IIS Configuration • Template Queries • XSL Style sheets

  4. Agenda • Support for XDR schemas/XML Views • XPath queries against these schemas. • XML for SQL Web Release • Bulk Load • Updategram • ADO programming methods (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: SELECT oh.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 <row /> 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. • Contains Tag and Parent meta-data • Tag: Tag number of current element • Parent: Tag number of parent element • 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], NULL [OrderDetail!2!ProductId], NULL [OrderDetail!2!UnitPrice], NULL [OrderDetail!2!Quantity] FROM Orders oh WHERE oh.CustomerId = ‘ANTON’ UNION ALL SELECT 2, 1, oh.CustomerID, oh.OrderId, od.ProductID, od.UnitPrice, od.Quantity FROM Orders oh INNER JOIN [Order Details] od ON oh.orderid = od.orderid WHERE CustomerId = ‘ANTON’ ORDER BY [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 • Process an internal representation • exec sp_xml_preparedocument • Parse the XML document • OpenXML Rowset function • 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 • Define template queries • Define style sheets • Make HTTP request

  20. Configure an IIS Virtual Root DEMO

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

  22. HTTP Access to Data • 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

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

  24. What are Template Queries? • 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 • Automatic formatting of the XML header information • Templates simplify the HTTP request • Templates have better support parameters

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

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

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

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

  30. How to use XML Views • http://server/vroot/vname/xpath?parameters • Vname is a direct reference to the schema file • Xpath is the xpath query • 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 • UpdateGrams • Bulk Load XML support • 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 <Before> and <After> blocks • Passing Parameters

  34. Writing Data withUpdate Grams • Update grams (example) <ROOT xmlns:updg="urn:schemas-microsoft-com:xml-updategram"> <updg:sync mapping-schema="SampleSchema.xml" > <updg:before> </updg:before> <updg:after> <Customer CustID="AAAAA" Company="Bottom-Dollar Markets" /> </updg:after> </updg:sync> </ROOT>

  35. Miscellaneous Data Retreival:OLAP datasp_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 • Uses ADO Stream Object • Requires ADO 2.6 • Stream Object defined as a property of the Command Object • XML Data placed in the Stream Object • Obtained using ReadText

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

  39. ADO XML Stream Support • Can persist directly to an ADO Stream Object • XML extracted using Stream ReadText • 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 • Recordset.Save MSXML.DOMDocument, adPersistXML • Can perform direct XSL transform for HTML based components

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

  42. ADO XML Programming DEMO

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

  44. Feedback / Questions ?