Download presentation
Presentation is loading. Please wait.
Published byDuane Stewart Modified over 9 years ago
1
SQLXML XML Technology For SQL Server Brian Moore Developer and Platform Strategy Group Microsoft Corporation
2
Agenda SQLXML Overview SQLXML Overview SQLXML Technologies SQLXML Technologies Bulkload Data with SQLXML Bulkload Data with SQLXML Web Services with SQLXML Web Services with SQLXML
3
Converging Data Models SQLServer RowSet SQL XMLFilesXPathXML XMLView
4
SQLXML Overview Provides a rich XML view of relational data Provides a rich XML view of relational data Benefits of XML – extensible, platform independent format of your data Semi-structured, hierarchical view of flat relational data Semi-structured, hierarchical view of flat relational data Two-way access – query and update Two-way access – query and update Multiple access mechanisms Multiple access mechanisms HTTP, ADO, ADO.NET, SOAP
5
SQLXML Technologies T-SQL Language Extensions T-SQL Language Extensions FOR XML SQL language extension to retrieve XML instead of rowsets OpenXML Rowset provider for in-memory XML documents XML Views and XPath XML Views and XPath Work with your relational database as if it was XML file (through annotated schema) Updategrams/Diffgrams Updategrams/Diffgrams Update database through XML View Bulkload Bulkload Shred large XML files into existing tables
6
Configuring SQLXML
7
Agenda SQLXML Overview SQLXML Overview SQLXML Technologies SQLXML Technologies Bulkload Data with SQLXML Bulkload Data with SQLXML Web Services with SQLXML Web Services with SQLXML
8
SQLXML Technologies FOR XML Language Extension FOR XML Language Extension HTTP Access via URL HTTP Access via URL SQL Query Templates XPath Query ADO / OLEDB ADO / OLEDB SQLXML Managed Classes SQLXML Managed Classes Updategram/Diffgram/Bulkload Updategram/Diffgram/Bulkload SOAP SOAP
9
FOR XML Query T-SQL Language Extension T-SQL Language Extension SELECT… FROM… WHERE… ORDER BY… FOR XML (RAW | AUTO [, ELEMENTS] | NESTED [, ELEMENTS] | EXPLICIT) [, XMLData] [, BINARY base64]) SELECT… FROM… WHERE… ORDER BY… FOR XML (RAW | AUTO [, ELEMENTS] | NESTED [, ELEMENTS] | EXPLICIT) [, XMLData] [, BINARY base64])
10
Using FOR XML Using FOR XML syntax from SQL Managed Classes Using FOR XML syntax from SQL Managed Classes SqlConnection Conn = new SqlConnection(ConnStr); SqlCommand cmd = new SqlCommand("SELECT * FROM Authors FOR XML AUTO", Conn); Conn.Open(); XmlReader r = cmd.ExecuteXmlReader(); SqlConnection Conn = new SqlConnection(ConnStr); SqlCommand cmd = new SqlCommand("SELECT * FROM Authors FOR XML AUTO", Conn); Conn.Open(); XmlReader r = cmd.ExecuteXmlReader();
11
HTTP Access Via URL URL Query URL Query Template Template XML View XML View http://localhost/demos?sql=SELECT * FROM Customers FOR XML AUTO &root=CustomerList http://localhost/demos?sql=SELECT * FROM Customers FOR XML AUTO &root=CustomerList http://server/vroot/vname/template.xml?params http://server/vroot/vname/schema.xsd/Customer[@ID='ALFKI']?params
12
XML Templates <root xmlns:sql="urn:schemas-microsoft-com:xml-sql" sql:xsl="[path to XSLT file]" > WA SELECT CompanyName, ContactName, Phone FROM Customers AS Customer WHERE Region LIKE @state FOR XML AUTO /Customers[@Region=$state] <root xmlns:sql="urn:schemas-microsoft-com:xml-sql" sql:xsl="[path to XSLT file]" > WA SELECT CompanyName, ContactName, Phone FROM Customers AS Customer WHERE Region LIKE @state FOR XML AUTO /Customers[@Region=$state]
13
XML Views Map between relational data and XML Map between relational data and XML Declarative Declarative Noninvasive Noninvasive No changes to legacy data sources No control over DB Server required XML View is an XML Schema XML View is an XML Schema XDR for SQL Server 2000 and SQLXML 1.0 XSD for SQLXML 2.0 and beyond
14
XML Views Default Mapping Example CustID A NULL B XML View Relational Data Customers Table <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:mapping-schema"> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:mapping-schema">
15
XML Views Explicit Mapping Example strCustID A NULL B Relational Data tblCustomers Table XML View <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:mapping-schema"> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:mapping-schema">
16
Join Example <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:mapping-schema"> <msdata:relationship parent="Customers" parent-key="CustomerID" child="Orders" child-key="CustomerID" /> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:mapping-schema"> <msdata:relationship parent="Customers" parent-key="CustomerID" child="Orders" child-key="CustomerID" />
17
XPath Use XPath to query SQL Database as if it was an XML file Use XPath to query SQL Database as if it was an XML file Each query translates into a SQL statement Each query translates into a SQL statement XPath XPath /Customer/Order[@OrderID=‘10692’]
18
SQLXML Technologies
19
Agenda SQLXML Overview SQLXML Overview SQLXML Technologies SQLXML Technologies Bulkload Data with SQLXML Bulkload Data with SQLXML Web Services with SQLXML Web Services with SQLXML
20
Application Scenario Business to Business Data Interchange XSDSchema Annotations + =MappingSchemaSQLServer XML Results + XPATH/Customers Query SQLServer Send Bulkload
21
XML Bulkload Bulkload XML documents into a SQL Server database via the XML View Bulkload XML documents into a SQL Server database via the XML View Just like traditional bulkload, except supports hierarchical relationships and semi-structured data Just like traditional bulkload, except supports hierarchical relationships and semi-structured data Scriptable COM object Scriptable COM object Requires P/Invoke in.NET Performance is about 75% of traditional bulkload Performance is about 75% of traditional bulkload Can use or ignore database constraints Can use or ignore database constraints
22
Bulkload Data with SQLXML
23
Agenda SQLXML Overview SQLXML Overview SQLXML Technologies SQLXML Technologies Bulkload Data with SQLXML Bulkload Data with SQLXML Web Services with SQLXML Web Services with SQLXML
24
Web Services with SQLXML WSDL file describing each SPROC or template exposed WSDL file describing each SPROC or template exposed Tool to choose which SPROC or template to expose Tool to choose which SPROC or template to expose SQLServer IIS/ISAPI SOAPMessage Message SP Template WSDL Client
25
Web Services with SQLXML
26
Call To Action Take the next step with SQL Server Web Services for your application Take the next step with SQL Server Web Services for your application Meet with the Microsoft technical team to discuss an Architectural Design Session or a Proof of Concept at the Microsoft Technology Center Download SQLXML 3.0 SP2 Download SQLXML 3.0 SP2 http://www.microsoft.com/sql/downloads/ For more information, please email For more information, please email scdlite@microsoft.com Slides available at Slides available at http://www.microsoft.com/usa/southcentral http://www.elysiumsystems.com
27
SQL Server Summit Brought To You By:
28
© 2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.
29
Additional Slides
30
Additional Slides SQLXML Overview
31
SQLXML Architecture Query Processor Annotated XSD Mapping Schemas XPath XQuery(Future) Query XML SQL Server SQL Server Rowsets FOR XML SQLQueries Queries SQLQueries Queries XMLBulkload BCP/SQLXML Updategrams/Diffgrams SQL update/ insert/ delete XML
32
Additional Slides FOR XML
33
For XML Raw Mode One element per row in the result set One element per row in the result set No nested elements Columns/values in result set are attributes/values on the Columns/values in result set are attributes/values on the Similar to row set but in XML format Similar to row set but in XML format............
34
For XML Auto Mode Supports nested XML output Supports nested XML output Nesting determined by ordering of columns in SELECT clause Table/View name in database used for the element name Column names used for attributes Change names using table and column aliases......
35
For XML Nested Mode Similar to Auto Mode Similar to Auto Mode Expanding query result into XML format moved from SQL Server to middle tier (client-side) Not all metadata in the database is available on the middle tier Base table name in database used for the element name Column names used for attributes Change column names only......
36
For XML Explicit Mode Provides complete control over format of XML result 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" Explicit mode requires the SELECT query to be written in a certain way to produce the "universal table format"
37
For XML Explicit Mode Example 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 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
38
Additional Slides Bulkload Data with SQLXML
39
Application Scenario Disconnected, Remote Clients SQLServer XML View for two-tier Data Source XML View for remote HTTP Data Source DisconnectedClientapplication RemoteSQLServer Logical Business Object (XML document Instance) XPath or Template queries via ADO UpdateGrams via ADO UpdateGrams via HTTP XPath or Template queries via HTTP
40
UpdateGrams Update relational data through XML View Update relational data through XML View Retrieve all customers as XML File Change a few customers in XML File Update relational data Translated into one or more INSERT, UPDATE, and DELETE statements behind the scenes Translated into one or more INSERT, UPDATE, and DELETE statements behind the scenes Relational operations are transparent to the user Relational operations are transparent to the user Optimistic concurrency control Optimistic concurrency control
41
DiffGrams Like UpdateGrams, but uses a different XML grammer to express updates Like UpdateGrams, but uses a different XML grammer to express updates Can be generated from an ADO.NET DataSet Can be generated from an ADO.NET DataSet Translated into one or more INSERT, UPDATE, and DELETE statements behind the scenes Translated into one or more INSERT, UPDATE, and DELETE statements behind the scenes Relational operations are transparent to the user Relational operations are transparent to the user Optimistic concurrency control Optimistic concurrency control
42
Updategrams <updg:sync mapping-schema="schema.xsd" xmlns:updg="urn:schemas-microsoft-com:xml-updategram"> <updg:sync mapping-schema="schema.xsd" xmlns:updg="urn:schemas-microsoft-com:xml-updategram">
43
Diffgrams <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Customers diffgr:id="Customers1" msdata:rowOrder="0" diffgr:hasChanges="modified"> ALFKI New Company ALFKI Alfreds Futterkiste <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Customers diffgr:id="Customers1" msdata:rowOrder="0" diffgr:hasChanges="modified"> ALFKI New Company ALFKI Alfreds Futterkiste
44
Additional Slides SQLXML Managed Classes
45
SqlXmlAdapter Dataset Fill Update SQLXML Managed Classes XmlReader Database SqlCommand FOR XML XMLVIEW SqlXmlCommand XML XPath XQueryTemplate XML
46
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. 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.
47
Using Templates from.NET SqlXmlCommand cmd = new SqlXmlCommand(ConnStr); cmd.CommandType = SqlXmlCommandType.Template; cmd.CommandStream = new FileStream("tmpl.xml", FileMode.Open, FileAccess.Read); cmd.ExecuteToStream(Response); SqlXmlCommand cmd = new SqlXmlCommand(ConnStr); cmd.CommandType = SqlXmlCommandType.Template; cmd.CommandStream = new FileStream("tmpl.xml", FileMode.Open, FileAccess.Read); cmd.ExecuteToStream(Response);
48
XPath Using the 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(); 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();
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.