Presentation is loading. Please wait.

Presentation is loading. Please wait.

Dev399 SQLXML: XML Views and Relational Data Irwin Dolobowsky Program Manager Webdata Group Microsoft Corporation.

Similar presentations


Presentation on theme: "Dev399 SQLXML: XML Views and Relational Data Irwin Dolobowsky Program Manager Webdata Group Microsoft Corporation."— Presentation transcript:

1 Dev399 SQLXML: XML Views and Relational Data Irwin Dolobowsky Program Manager Webdata Group Microsoft Corporation

2 Overview of talk Goals of presentation: Learn about the XML View Examine leveraging Xml View in application scenarios Agenda: A survey of the SqlXml features that provide the XML View Discuss strengths and weaknesses of each feature See the features in action

3 SqlXml – A Quick History The project started in 1998 to solve XML to relational mapping problem Version 1.0 of product shipped as part of SQL Server 2000 Both Client and Server functionality New “Web Releases” of client functionality are available via the MSDN web site: http://www.msdn.com/sqlxml Three fully supported releases since the initial Sql Server 2000 release.

4 Different kinds of data Structured Highly regular, homogeneous structure Rowsets, Comma delimited files Semi-Structured Heterogeneous structure Sparse Occurrences of data HTML and XML documents Unstructured Documents/Content

5 The Two Worlds SQLServer RowSet SQL Structured world Language Data storage Data output Semi- Structured world XMLFiles XPath XML/HTML XMLView SQLXML – Bringing worlds together

6 What is the “XML View” ? The XML view is a virtual collection of XML documents created over a SQL Server database The XML view can completely encapsulate and hide the underlying relational structures The resulting XML documents can easily represent hierarchical, semi-structured content

7 The XML View - Architecture SQLServer Relation tables Relation views Relation Storedprocs For XML Queries AnnotatedXSDMappingSchemas XPath Queries Updategrams XMLBulkload XSLT

8 Annotated Mapping Schemas Defines an XML View of a database Uses XSD schemas with special annotations Annotations specify the mapping between xml and relational data XPath is used to query the XML View Changes to an XML View are persisted to database via Updategrams

9 Tables and Columns Default mapping: Elements map to tables of the same name Attributes map to columns in the table Explicit mapping: sql:relation maps to a table sql:field maps to a column

10 Default Mapping CustID ------ A NULL B XML View Relational Data: Customers Table

11 Explicit Mapping <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema“ xmlns:sql="urn:schemas-microsoft-com:mapping-schema“> pkCustID ------ A NULL B Relational Data: tblCustomers Table

12 Join Relationships Require an explicit annotation to describe the join: < sql:relationship parent=“Table1" parent-key=“pk" child=“Table2” child-key=“fk" /> Expresses the SQL join SELECT * FROM Table1 JOIN Table2 ON Table1.pk= Table2.fk

13 Join Example <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sql="urn:schemas-microsoft-com:mapping-schema"> <sql:relationship parent="Customers" parent-key="CustomerID" child="Orders" child-key="CustomerID" />

14 Some other annotations Ignore schema components: Query on field which is not returned in results: Introduce XML elements that do not map to the database: …

15 Can even map Open Content Map SQL data as XML text: Notes ------

16 XPath Navigation language (used by XSLT to select nodes in an XML document) Compact syntax resembles file paths or URLs: /Customer/Order[@OrderID=‘10692’] Each XPath translates into a SQL query using FOR XML EXPLICIT to construct the XML For complete details on XPath, see the W3C specification at: http://www.w3.org/TR/XPath

17 XPath and XML Views Irwin Dolobowsky Program Manager Webdata demo demo

18 XPath and the XML View in real life The shape of the generated XML instance document can be very different then the underlying relation storage Multiple databases (with different schemas) can provide a common XML view Much easier to develop and maintain than For XML Explicit queries

19 For XML – Explicit Mode Provides complete control over format of XML result Columns can be individually mapped to attributes or sub elements Supports arbitrary nesting Collapses/hoists hierarchy Constructs ID/IDREF relationships Explicit mode requires the SELECT query to be written in a certain way to produce the “universal table format”

20 For XML – Explicit Mode SELECT 1 as TAG, NULL as PARENT, CustomerID AS [Customer!1!cid!id], CompanyName AS [Customer!1!name!element], NULL AS [Order!2!oid!id] FROM Customers WHERE CustomerID = 'ALFKI' OR CustomerID='BOLID' UNION ALL SELECT 2, 1, Customers.CustomerID, NULL, 'O-'+CAST(Orders.OrderID AS varchar(32)) FROM Customers INNER JOIN Orders ON Customers.CustomerID=Orders.CustomerID WHERE Customers.CustomerID = 'ALFKI' OR Customers.CustomerID='BOLID' ORDER BY [Customer!1!cid!id] FOR XML explicit

21 Updategrams & XML Views Modify the database through the XML View Declare before and after images of the XML (what it is now, and what you want it to be) Optimistic concurrency control ensures that the transaction takes place only if the before image matches the current database state Each updategram is translated into one or more INSERT, UPDATE, and DELETE statements, carried out as a single transaction

22 Updategrams And XMLViews

23 Updategrams in real life Enables persisting of changes to XML view by disconnected clients Can easily represent hierarchical changes to data Existing programming model is limited, client must generate updategrams manually

24 XML Bulkload & XML Views Bulkload XML documents into a SQL Server database via the XML View Just like traditional bulkload, except supports hierarchical relationships and semi-structured data Scriptable COM object Performance is about 75% of traditional bulkload

25 XML Bulkload & XML Views Sample Bulkload vbs script: set objBL = CreateObject("SQLXMLBulkLoad.SQLXMLBulkLoad") objBL.ConnectionString = "provider=SQLOLEDB.1;data source=(local);database=tempdb;uid=sa;pwd=" objBL.ErrorLogFile = "error.xml" objBL.XMLFragment = True objBL.CheckConstraints = False objBL.Execute "schema.xsd", "data.xml" Set objBL = Nothing

26 XML Bulkload in real life Very fast, efficient way to shred XML and insert in to a SQL Server database XML Views allows the publisher and consumer of the data to have different database schemas Currently, does not support “max errors” so bulkload processing is stopped by first problem

27 Data Access Methods HTTP Access via URL SQL Query XPath Query Templates ADO / OLEDB.NET access through SQLXML Managed Classes SOAP

28 SQLXML Managed Classes SqlXmlCommand cmd = new SqlXmlCommand(ConnStr); cmd.CommandType = SqlXmlCommandType.XPath cmd.CommandText = “/Customer[@CustID=‘ALFKI’]”; cmd.SchemaPath = “nwind.xml”; cmd.RootTag = “ROOT”; cmd.XslPath = “Customers.xsl”; XmlReader r = cmd.ExecuteXmlReader(); // or DataSet ds = new DataSet(); SqlXmlAdapter ad = new SqlXmlAdapter(cmd); ad.Fill(ds); //… ad.Update(ds); // DataSet generates diffgram

29 XML View Application Scenario – A data driven web site Problem: Need to publish data driven web site with minimal coding Control of SQL Server database api (table, stored procs, views) is limited Solution: Define an XML View and apply XSLT to the instance documents to generate HTML User communicates with web site through template parameters

30 XML View Application Scenario – Disconnected Clients: Problem: Client application is required to consume data from different SQL Server databases Client may need disconnected, HTTP access to SQL Server Solution: Define common XML View Client queries with XPath, and submits changes via updategrams using SQL Server HTTP access

31 XML View Application Scenario – Data Interchange: Problem: Want to exchange large amounts of data with other applications Need to decouple the logical business from the database schema Solution: Run XPath queries against XML View to generate data Incrementally load into destination database using XML View (different mappings) and XML Bulkload

32 Using the Xml View to decouple business objects from database demo demo

33 A decoupled architecture Class Employee { int ID, int ID, string lastName, string lastName, string firstName, string firstName, …} Class EmployeeAddress { string street, string street, string city, string city, string state, string state, …. ….} <Employee> 23 23 Jones Jones Jeff Jeff 122 Oak 122 Oak Tacoma Tacoma WA WA </Employee> SQLServer CLR Business Objects Relational Database XML SqlXml Xml Serialization

34 Demo is available online Complete Demo available at MSDN Extreme Xml column- http://msdn.microsoft.com/columns/xml.asp http://msdn.microsoft.com/columns/xml.asp April column – “Death, Taxes and Relational databases, Part 1” uses server side technologies OpenXml and For Xml. July column will use Annotated Mapping schemas and updategrams. Extreme Xml column contains SqlXml specific column approximately four times a year.

35 Other SqlXml resources Download latest SqlXml release at http://www.msdn.com/sqlxml http://www.msdn.com/sqlxml Learn about product via documentation and supporting material at SqlXml SqlXml books “The Guru's Guide to SQL Server(TM) Stored Procedures, XML, and HTML” - Pearson Education “Programming Microsoft SQL Server 2000 with XML”, Second Edition – Microsoft Press

36 SqlXml Community Resources http://msdn.microsoft.com/sqlxml Newsgroups microsoft.public.sqlserver.xml microsoft.public.dotnet.xml http://www.SqlXml.org SqlXml Blog http://blogs.gotdotnet.com/aconrad

37 Community Resources http://www.microsoft.com/communities/default.mspx Most Valuable Professional (MVP) http://www.mvp.support.microsoft.com/ Newsgroups Converse online with Microsoft Newsgroups, including Worldwide http://www.microsoft.com/communities/newsgroups/default.mspx User Groups Meet and learn with your peers http://www.microsoft.com/communities/usergroups/default.mspx

38 Ask The Experts Get Your Questions Answered After this talk ATE – Thursday July 3 rd 11:00-14:00

39 evaluations evaluations

40 © 2003 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.


Download ppt "Dev399 SQLXML: XML Views and Relational Data Irwin Dolobowsky Program Manager Webdata Group Microsoft Corporation."

Similar presentations


Ads by Google