SlideShare a Scribd company logo
What’s New for XML in SQL Server 2008?<br />White Paper<br />Published: August 2008<br />Summary: Microsoft® SQL Server™ 2008 builds on the extensive support for XML by extending support for XML schema validation and XQuery, and by enhancing the xml data type.<br />.<br />Contents<br /> TOC  quot;
1-2quot;
 Introduction PAGEREF _Toc205573720  1<br />The Evolution of SQL Server XML Capabilities PAGEREF _Toc205573721  1<br />XML Functionality in SQL Server 2000 PAGEREF _Toc205573722  1<br />XML Functionality in SQL Server 2005 PAGEREF _Toc205573723  2<br />XML Functionality in SQL Server 2008 PAGEREF _Toc205573724  5<br />XML Schema Validation Enhancements PAGEREF _Toc205573725  5<br />Lax Validation Support PAGEREF _Toc205573726  6<br />Full xs:dateTime Support PAGEREF _Toc205573727  7<br />Union and List Types PAGEREF _Toc205573728  8<br />XQuery Enhancements PAGEREF _Toc205573729  10<br />XML DML Enhancements PAGEREF _Toc205573730  11<br />Conclusion PAGEREF _Toc205573731  12<br />Introduction<br />Microsoft introduced XML-related capabilities in Microsoft SQL Server 2000 with the FOR XML and OPENXML Transact-SQL keywords, which enabled developers to write Transact-SQL code to retrieve a query result as a stream of XML, and to shred an XML document into a rowset. These XML capabilities were extended significantly in SQL Server 2005 with the introduction of a native xml data type that supports XSD schema validation, XQuery-based operations, and XML indexing. SQL Server 2008 builds on the XML capabilities of previous releases and provides enhancements to meet the challenges that customers have faced when storing and manipulating XML data in the database.<br />The Evolution of SQL Server XML Capabilities<br />The XML features of SQL Server have evolved with each version of SQL Server since SQL Server 2000. Before we examine the enhancements in SQL Server 2008, it might be useful to chart the evolution of XML functionality through the previous versions.<br />XML Functionality in SQL Server 2000<br />In SQL Server 2000, Microsoft introduced the FOR XML and OPENXML Transact-SQL keywords. FOR XML is an extension to the SELECT statement that returns the query results as a stream of XML as shown in the following example.<br />SELECT ProductID, ProductName<br />FROM Products Product<br />FOR XML AUTO<br />This query returns an XML fragment like the following example.<br /><Product ProductID=quot;
1quot;
 ProductName=quot;
Widgetquot;
/><br /><Product ProductID=quot;
2quot;
 ProductName=quot;
Sprocketquot;
/><br />The OPENXML function performs the opposite function to the FOR XML clause by creating a rowset from an XML document, as shown in the following example.<br />DECLARE @doc nvarchar(1000)<br />SET @doc = '<Order OrderID = quot;
1011quot;
><br /><Item ProductID=quot;
1quot;
 Quantity=quot;
2quot;
/><br /><Item ProductID=quot;
2quot;
 Quantity=quot;
1quot;
/><br /></Order>'<br />DECLARE @xmlDoc integer<br />EXEC sp_xml_preparedocument @xmlDoc OUTPUT, @doc<br />SELECT * FROM<br />OPENXML (@xmlDoc, 'Order/Item', 1)<br />WITH<br />(OrderID integer '../@OrderID',<br /> ProductID integer,<br /> Quantity integer)<br />EXEC sp_xml_removedocument @xmlDoc<br />Note the use of the sp_xml_preparedocument and sp_xml_removedocument stored procedures to create an in-memory representation of the node tree for the XML document. This Transact-SQL code returns the following rowset.<br />OrderIDProductIDQuantity101112101121<br />XML Functionality in SQL Server 2005<br />In SQL Server 2005, the FOR XML feature was enhanced with new options for root elements and element names, the ability to nest FOR XML calls so you can build complex hierarchies, and a new PATH mode that enables you to define the structure of the XML to be retrieved by using XPath syntax, as shown in the following example.<br />SELECT ProductID AS '@ProductID',<br />ProductName AS 'ProductName'<br />FROM Products<br />FOR XML PATH ('Product'), ROOT ('Products')<br />This query returns the following XML.<br /><Products><br /><Product ProductID=quot;
1quot;
><br /><ProductName>Widget</ProductName><br /></Product><br /><Product ProductID=quot;
2quot;
><br /><ProductName>Sprocket</ProductName><br /></Product><br /></Products><br />In addition to enhancing the existing XML features that had been introduced in SQL Server 2000, SQL Server 2005 added a new, native xml data type that enables you to create variables and columns for XML data, as shown in the following example.<br />CREATE TABLE SalesOrders<br />(OrderID integer PRIMARY KEY,<br /> OrderDate datetime,<br /> CustomerID integer,<br /> OrderNotes xml)<br />You can use the xml data type to store markup documents or semi-structured data in the database. Columns and variables can be used for untyped XML or typed XML, the latter of which is validated against an XML Schema Definition (XSD) schema. To define the schemas for data validation, developers can use the CREATE XML SCHEMA COLLECTION statement, as shown in the following example.<br />CREATE XML SCHEMA COLLECTION ProductSchema AS<br />'<?xml version=quot;
1.0quot;
 encoding=quot;
UTF-16quot;
?><br /><xs:schema xmlns:xs=quot;
http://www.w3.org/2001/XMLSchemaquot;
><br />  <!-- schema declarations go here --><br /></xs:schema>'<br />After creating a schema collection, you can associate an xml variable or column with the schema declarations it contains by referencing the schema collection as shown in the following example.<br />CREATE TABLE SalesOrders<br />(OrderID integer PRIMARY KEY,<br /> OrderDate datetime,<br /> CustomerID integer,<br /> OrderNotes xml(ProductSchema))<br />Typed XML is validated against the declarations in the associated schema collection when values are inserted or updated, which makes it possible to enforce business rules about the structure of XML data for compliance or compatibility reasons.<br />The xml data type also provides a number of methods, which you can use to query and manipulate the XML data in an instance. For example, you can use the query method to query the XML in an instance of the xml data type, as shown in the following example.<br />declare @x xml<br />set @x=<br />'<Invoices><br /><Invoice><br /><Customer>Kim Abercrombie</Customer><br /><Items><br /><Item ProductID=quot;
2quot;
 Price=quot;
1.99quot;
 Quantity=quot;
1quot;
 /><br /><Item ProductID=quot;
3quot;
 Price=quot;
2.99quot;
 Quantity=quot;
2quot;
 /><br /><Item ProductID=quot;
5quot;
 Price=quot;
1.99quot;
 Quantity=quot;
1quot;
 /><br /></Items><br /></Invoice><br /><Invoice><br /><Customer>Margaret Smith</Customer><br /><Items><br /><Item ProductID=quot;
2quot;
 Price=quot;
1.99quot;
 Quantity=quot;
1quot;
/><br /></Items><br /></Invoice><br /></Invoices>'<br />SELECT @x.query(<br />'<CustomerList><br />{<br />for $invoice in /Invoices/Invoice<br />return $invoice/Customer<br />}<br /></CustomerList>')<br />The query in this example uses an XQuery expression that finds each Invoice element in the document and returns an XML document that contains the Customer element from each Invoice element, as shown in the following example.<br /><CustomerList><br />  <Customer>Kim Abercrombie</Customer><br />  <Customer>Margaret Smith</Customer><br /></CustomerList><br />Another significant XML-related feature that was introduced in SQL Server 2005 is support for XML indexes. You can create primary and secondary XML indexes for columns of type xml to enhance XML query performance. A primary XML index is a shredded representation of all of the nodes in an XML instance, which the query processor can use to quickly find nodes within an XML value. After you have created a primary XML index, you can create secondary XML indexes to improve the performance of specific types of query. The following example creates a primary XML index, and a secondary XML index of type PATH, which can improve performance of queries that use XPath expressions to identify nodes in an XML instance.<br />CREATE PRIMARY XML INDEX idx_xml_Notes<br />ON SalesOrders (Notes)<br />GO<br />CREATE XML INDEX idx_xml_Path_Notes<br />ON SalesOrders (Notes)<br />USING XML INDEX idx_xml_Notes<br />FOR PATH<br />GO<br />XML Functionality in SQL Server 2008<br />The XML functionality that was introduced in SQL Server 2000 and SQL Server 2005 has been enhanced in SQL Server 2008. Key XML-related enhancements in SQL Server 2008 include:<br />Improved schema validation capabilities<br />Enhancements to XQuery support<br />Enhanced functionality for performing XML data manipulation language (DML) insertions<br />The rest of this whitepaper examines these enhancements and demonstrates how you can use them to implement better XML solutions in SQL Server 2008.<br />XML Schema Validation Enhancements<br />You can validate XML data by enforcing compliance with one or several XSD schemas. A schema defines the permissible XML elements and attributes for a particular XML data structure, and is often used to ensure that XML documents contain all of the required data elements in the correct structure.<br />SQL Server 2005 introduced validation of XML data through the use of XML schema collections. The general approach is to a create schema collection that contains the schema rules for your XML data by using the CREATE XML SCHEMA COLLECTION statement, and then to reference the schema collection name when you define an xml column or variable that must conform to the schema rules in the schema collection. SQL Server then validates any data that is inserted or updated in the column or variable against the schema declarations in the schema collection.<br />XML Schema support in SQL Server 2005 implemented a broad subset of the full XML Schema specification, and covered the most common XML validation scenarios. SQL Server 2008 extends that support to include the following additional schema validation requirements that have been identified by customers:<br />Support for lax validation<br />Full support for dateTime, time and date validation, including preservation of time zone information<br />Improved Support for union and list types<br />Lax Validation Support<br />XML Schemas support wildcard sections in XML documents through the any, anyAttribute, and anyType declarations. For example, consider the following XML schema declaration.<br /><xs:complexType name=quot;
Orderquot;
 mixed=quot;
truequot;
><br />  <xs:sequence><br />    <xs:element name=quot;
CustomerNamequot;
/><br />    <xs:element name=quot;
OrderTotalquot;
/><br />    <xs:any namespace=quot;
##otherquot;
 processContents=quot;
skipquot;
 <br />minOccurs=quot;
0quot;
 maxOccurs=quot;
unboundedquot;
/><br />  </xs:sequence><br /></xs:complexType><br />This schema declaration defines an XML element named Order, which must contain sub-elements named CustomerName and OrderTotal. Additionally, the element can contain an unlimited number of other elements that belong to a different namespace than the one to which the Order type belongs. The following XML shows an XML document that contains an instance of an Order element as defined by this schema declaration. Note that the order also contains a shp:Delivery element, which is not explicitly defined in the schema.<br /><Invoice xmlns=quot;
http://adventure-works.com/orderquot;
<br />xmlns:shp=quot;
http://adventure-works.com/shippingquot;
><br />  <Order><br />    <CustomerName>Graeme Malcolm</CustomerName><br />    <OrderTotal>299.99</OrderTotal><br />    <shp:Delivery>Express</shp:Delivery><br />  </Order><br /></Invoice><br />Validation for wildcard sections depends on the processContents attribute for the wildcard section in the schema definition. In SQL Server 2005, schemas can use processContents values of skip and strict for any and anyAttribute declarations. In the previous example, the processContents attribute for the wildcard element has been set to skip, so no attempt to validate the contents of that element is made. Even if the schema collection includes a declaration for the shp:Delivery element (for example, defining a list of valid delivery methods), the element is not validated unless the declaration for the wildcard in the Order element has its processContents attribute set to strict.<br />SQL Server 2008 adds support for a third validation option. By setting the processContents attribute for a wildcard section to lax, you can enforce validation for any elements that have schema declarations associated with them, but ignore any elements that are not defined in the schema. To continue the previous example, if you set the processContents attribute for the wildcard element declaration in the schema to lax and add a declaration for the shp:Delivery element, shp:Delivery element in the XML document is validated. However, if instead of the shp:Delivery element, the document includes an element that is not defined in the schema, the element is ignored.<br />In addition, the XML Schema specification defines that the anyType declaration has lax processing of its content model. SQL Server 2005 does not support lax processing, so the content is validated strictly instead. SQL Server 2008 does support lax processing of the anyType contents, and so the content is validated correctly.<br />Full xs:dateTime Support<br />You can use the dateTime data type in an XML schema to define date and time data. Date and time data is expressed in the format 2007-08-01T09:30:00:000Z, which represents the 1st of August 2007 at 9:30 in the morning in the coordinated universal time zone (UTC), which is indicated by the Z. Other time zones are represented by the time difference from UTC, so for example you can represent 6:00 in the morning on December 25th 2007 in Pacific Standard Time (which is 8 hours behind UTC) with the value 2007-12-25T06:00:00:000-8:00.<br />The XML Schema specification defines the time zone component of the dateTime, date and time data types as optional. However, in SQL Server 2005 you must provide a time zone for dateTime, time and date data. Additionally, SQL Server 2005 does not preserve the time zone information for your data for dateTime or time, but normalizes it to UTC (so for example, if your XML contains the value 2007-12-25T06:00:00:000-8:00, SQL Server 2005 normalizes this as 2007-12-25T14:00:00:000Z.) In SQL Server 2008, these limitations have been removed, so you can omit the time zone information when you store dateTime, date or time data, and any time zone information that you do provide is preserved.<br />Union and List Types<br />You can use XML schemas to define data types for your XML data that allow a limited set of values to be assigned to multi-value elements and attributes. For example, you might define a sizeListType type that restricts the list of possible values that can be assigned to an AvaliableSizes element in the product definition to S, M, and L. SQL Server 2005 supports XML schemas that contain these simple type definitions and restrictions. For example, you can use a list type to define the valid sizes for a product as shown in the following example.<br /><xs:simpleType name=quot;
sizeListTypequot;
><br />  <xs:list><br />    <xs:simpleType><br />      <xs:restriction base=quot;
xs:stringquot;
><br />        <xs:enumeration value=quot;
Squot;
/><br />        <xs:enumeration value=quot;
Mquot;
/><br />        <xs:enumeration value=quot;
Lquot;
/><br />      </xs:restriction><br />    </xs:simpleType><br />  </xs:list><br /></xs:simpleType><br />This schema declaration enables you to create an element that lists all of the sizes in which a product can be purchased as a list of values separated by white space, as shown in the following example:<br /><AvailableSizes>S M L</AvailableSizes><br />However, what if you want to support two different ways to express the size of a product? For example, suppose a cycling equipment retailer sells cycling clothes in small, medium, and large sizes, but also sells bicycles in numerical sizes relating to the frame size (such as 18, 20, 22, and 24)? To enable you to accomplish this, SQL Server 2008 adds support for union types that contain list types, which you can use to merge multiple list type definitions and restrictions into a single type. For example, the following Transact-SQL code creates an XML schema collection that defines a productSizeType type in which valid values include a list of numeric sizes (18, 20, 22, and 24) and a list of named sizes (S, M, and L).<br />CREATE XML SCHEMA COLLECTION CatalogSizeSchema AS<br />N'<?xml version=quot;
1.0quot;
 encoding=quot;
UTF-16quot;
?><br /><xs:schema xmlns:xs=quot;
http://www.w3.org/2001/XMLSchemaquot;
><br /><xs:simpleType name=quot;
productSizeTypequot;
><br /><xs:union><br /><xs:simpleType><br />  <xs:list><br /><xs:simpleType><br />  <xs:restriction base=quot;
xs:integerquot;
><br /><xs:enumeration value=quot;
18quot;
/><br /><xs:enumeration value=quot;
20quot;
/><br /><xs:enumeration value=quot;
22quot;
/><br /><xs:enumeration value=quot;
24quot;
/><br />  </xs:restriction><br /></xs:simpleType><br />  </xs:list><br /></xs:simpleType><br /><xs:simpleType><br />  <xs:list><br /><xs:simpleType><br />  <xs:restriction base=quot;
xs:stringquot;
><br /><xs:enumeration value=quot;
Squot;
/><br /><xs:enumeration value=quot;
Mquot;
/><br /><xs:enumeration value=quot;
Lquot;
/><br />  </xs:restriction><br /></xs:simpleType><br />  </xs:list><br /></xs:simpleType><br /></xs:union><br /></xs:simpleType><br /></xs:schema>'<br />With this declaration in the schema, any elements based on the productSizeType can contain either kind of list; so both of the product elements in the following example would be valid instances of the productSizeType data type.<br /><Catalog><br />  <Product><br />    <ProductName>Road Bike</ProductName><br />    <AvailableSizes>22 24</AvailableSizes><br />  </Product><br />  <Product><br />    <ProductName>Cycling Jersey</ProductName><br />    <AvailableSizes>S M L</AvailableSizes><br />  </Product><br /></Catalog><br />Similarly, SQL Server 2008 supports schema declarations for list types that contain union types.<br />XQuery Enhancements<br />SQL Server 2005 introduced the xml data type, which provides a number of methods that you can use to perform operations on the XML data stored in a column or variable. Most of the operations you can perform use XQuery syntax to navigate and manipulate the XML data. The XQuery syntax supported by SQL Server 2005 includes the for, where, order by, and return clauses of the so called FLWOR expression, which you can use to iterate over the nodes in an XML document and return values.<br />SQL Server 2008 adds support for the let clause, which is used to assign values to variables in an XQuery expression such as the following example:<br />declare @x xml<br />set @x=<br />'<Invoices><br /><Invoice><br /><Customer>Kim Abercrombie</Customer><br /><Items><br /><Item ProductID=quot;
2quot;
 Price=quot;
1.99quot;
 Quantity=quot;
1quot;
 /><br /><Item ProductID=quot;
3quot;
 Price=quot;
2.99quot;
 Quantity=quot;
2quot;
 /><br /><Item ProductID=quot;
5quot;
 Price=quot;
1.99quot;
 Quantity=quot;
1quot;
 /><br /></Items><br /></Invoice><br /><Invoice><br /><Customer>Margaret Smith</Customer><br /><Items><br /><Item ProductID=quot;
2quot;
 Price=quot;
1.99quot;
 Quantity=quot;
1quot;
/><br /></Items><br /></Invoice><br /></Invoices>'<br />SELECT @x.query(<br />'<Orders><br />{<br />for $invoice in /Invoices/Invoice<br />let $count :=count($invoice/Items/Item)<br />order by $count<br />return<br /><Order><br />{$invoice/Customer}<br /><ItemCount>{$count}</ItemCount><br /></Order><br />}<br /></Orders>')<br />This example returns the following XML.<br /><Orders><br /><Order><br /><Customer>Margaret Smith</Customer><br /><ItemCount>1</ItemCount><br /></Order><br /><Order><br /><Customer>Kim Abercrombie</Customer><br /><ItemCount>3</ItemCount><br /></Order><br /></Orders><br />Note that SQL Server 2008 does not allow the assignment of constructed elements.<br />XML DML Enhancements<br />As well as being able to use XQuery expressions to perform operations on XML data, the xml data type supports the XML DML expressions insert, replace value of, and delete through its modify method. You can use these XML DML expressions to manipulate the XML data in an xml column or variable.<br />SQL Server 2008 adds support for using an xml variable in an insert expression to insert XML data into an existing XML structure. For example, suppose an xml variable named @productList contains the following XML:<br /><Products><br />  <Bike>Mountain Bike</Bike><br />  <Bike>Road Bike</Bike><br /></Products><br />You could use the following code to insert a new bike into the product list:<br />DECLARE @newBike xml<br />SET @newBike = '<Bike>Racing Bike</Bike>'<br />SET @productList.modify<br />('insert sql:variable(quot;
@newBikequot;
) as last into (/Products)[1]')<br />After running this code, the @productList variable would contain the following XML.<br /><Products><br />  <Bike>Mountain Bike</Bike><br />  <Bike>Road Bike</Bike><br />  <Bike>Racing Bike</Bike><br /></Products><br />Conclusion<br />SQL Server 2008 builds on the already comprehensive support for XML that was present in SQL Server 2005, and extends your ability to build powerful database solutions that combine relational data and XML. The improvements to XML schema support, as well as the enhancements to the xml data type provide benefits that application developers will find immensely appealing.<br />For more information:<br />http://www.microsoft.com/sql/<br />Please give us your feedback:<br />Did this paper help you? Tell us on a scale of 1 (poor) to 5 (excellent), how would you rate this paper and why have you given it this rating? For example:<br />Are you giving it a high rating because it has good examples, excellent screenshots, clear writing, or another reason? <br />Are you giving it a low rating because it has poor examples, fuzzy screenshots, unclear writing?<br />This feedback will help us improve the quality of white papers we release. Send feedback.<br />
Sql server 2008 r2 xml wp
Sql server 2008 r2 xml wp
Sql server 2008 r2 xml wp
Sql server 2008 r2 xml wp
Sql server 2008 r2 xml wp
Sql server 2008 r2 xml wp
Sql server 2008 r2 xml wp
Sql server 2008 r2 xml wp
Sql server 2008 r2 xml wp
Sql server 2008 r2 xml wp
Sql server 2008 r2 xml wp
Sql server 2008 r2 xml wp
Sql server 2008 r2 xml wp
Sql server 2008 r2 xml wp

More Related Content

What's hot

SQL
SQLSQL
Database Systems - SQL - DCL Statements (Chapter 3/4)
Database Systems - SQL - DCL Statements (Chapter 3/4)Database Systems - SQL - DCL Statements (Chapter 3/4)
Database Systems - SQL - DCL Statements (Chapter 3/4)
Vidyasagar Mundroy
 
Creating Purcahse Orders
Creating Purcahse OrdersCreating Purcahse Orders
Creating Purcahse OrdersEMAINT
 
SQL Programming
SQL ProgrammingSQL Programming
Sql presentation 1 by chandan
Sql presentation 1 by chandanSql presentation 1 by chandan
Sql presentation 1 by chandan
Linux international training Center
 
Detail Views
Detail ViewsDetail Views
Detail ViewsEMAINT
 
Detail view in distributed technologies
Detail view in distributed technologiesDetail view in distributed technologies
Detail view in distributed technologies
jamessakila
 
Excel 2007 Unit N
Excel 2007 Unit NExcel 2007 Unit N
Excel 2007 Unit N
Raja Waseem Akhtar
 
Sql basic best-course-in-mumbai
Sql basic best-course-in-mumbaiSql basic best-course-in-mumbai
Sql basic best-course-in-mumbai
vibrantuser
 
EHRI Conversion Tool
EHRI Conversion ToolEHRI Conversion Tool
EHRI Conversion Tool
EHRI
 
Data weave
Data weaveData weave
Data weave
himajareddys
 
Dbms practical list
Dbms practical listDbms practical list
Dbms practical list
RajSingh734307
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commandsBelle Wx
 
Get Started with Excel for PPC in 40 Minutes - Hero Conf London 2017
Get Started with Excel for PPC in 40 Minutes - Hero Conf London 2017Get Started with Excel for PPC in 40 Minutes - Hero Conf London 2017
Get Started with Excel for PPC in 40 Minutes - Hero Conf London 2017
Frederik Hyldig
 
Form personalization 395117_r12_updated1212
Form personalization 395117_r12_updated1212Form personalization 395117_r12_updated1212
Form personalization 395117_r12_updated1212
flower705
 
Internet Environment
Internet  EnvironmentInternet  Environment
Internet Environmentguest8fdbdd
 
Tips and Tricks
Tips and TricksTips and Tricks
Tips and TricksEMAINT
 
Customizing Forms
Customizing FormsCustomizing Forms
Customizing FormsEMAINT
 
Oracle SQL Part 3
Oracle SQL Part 3Oracle SQL Part 3
Oracle SQL Part 3
Gurpreet singh
 

What's hot (19)

SQL
SQLSQL
SQL
 
Database Systems - SQL - DCL Statements (Chapter 3/4)
Database Systems - SQL - DCL Statements (Chapter 3/4)Database Systems - SQL - DCL Statements (Chapter 3/4)
Database Systems - SQL - DCL Statements (Chapter 3/4)
 
Creating Purcahse Orders
Creating Purcahse OrdersCreating Purcahse Orders
Creating Purcahse Orders
 
SQL Programming
SQL ProgrammingSQL Programming
SQL Programming
 
Sql presentation 1 by chandan
Sql presentation 1 by chandanSql presentation 1 by chandan
Sql presentation 1 by chandan
 
Detail Views
Detail ViewsDetail Views
Detail Views
 
Detail view in distributed technologies
Detail view in distributed technologiesDetail view in distributed technologies
Detail view in distributed technologies
 
Excel 2007 Unit N
Excel 2007 Unit NExcel 2007 Unit N
Excel 2007 Unit N
 
Sql basic best-course-in-mumbai
Sql basic best-course-in-mumbaiSql basic best-course-in-mumbai
Sql basic best-course-in-mumbai
 
EHRI Conversion Tool
EHRI Conversion ToolEHRI Conversion Tool
EHRI Conversion Tool
 
Data weave
Data weaveData weave
Data weave
 
Dbms practical list
Dbms practical listDbms practical list
Dbms practical list
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
 
Get Started with Excel for PPC in 40 Minutes - Hero Conf London 2017
Get Started with Excel for PPC in 40 Minutes - Hero Conf London 2017Get Started with Excel for PPC in 40 Minutes - Hero Conf London 2017
Get Started with Excel for PPC in 40 Minutes - Hero Conf London 2017
 
Form personalization 395117_r12_updated1212
Form personalization 395117_r12_updated1212Form personalization 395117_r12_updated1212
Form personalization 395117_r12_updated1212
 
Internet Environment
Internet  EnvironmentInternet  Environment
Internet Environment
 
Tips and Tricks
Tips and TricksTips and Tricks
Tips and Tricks
 
Customizing Forms
Customizing FormsCustomizing Forms
Customizing Forms
 
Oracle SQL Part 3
Oracle SQL Part 3Oracle SQL Part 3
Oracle SQL Part 3
 

Viewers also liked

Suporte XML nativo no SQL Server 2014/2016
Suporte XML nativo no SQL Server 2014/2016Suporte XML nativo no SQL Server 2014/2016
Suporte XML nativo no SQL Server 2014/2016
Rogério Moraes de Carvalho
 
Sql Summit Clr, Service Broker And Xml
Sql Summit   Clr, Service Broker And XmlSql Summit   Clr, Service Broker And Xml
Sql Summit Clr, Service Broker And Xml
David Truxall
 
Managing database project with Visual Studio SSDT and TFS
Managing database project with Visual Studio SSDT and TFSManaging database project with Visual Studio SSDT and TFS
Managing database project with Visual Studio SSDT and TFS
Harry Zheng
 
SSDT unleashed
SSDT unleashedSSDT unleashed
SSDT unleashed
GomathiNayagam S
 
SSDT Workshop @ SQL Bits X (2012-03-29)
SSDT Workshop @ SQL Bits X (2012-03-29)SSDT Workshop @ SQL Bits X (2012-03-29)
SSDT Workshop @ SQL Bits X (2012-03-29)
Gert Drapers
 

Viewers also liked (6)

Welcome to SSDT
Welcome to SSDTWelcome to SSDT
Welcome to SSDT
 
Suporte XML nativo no SQL Server 2014/2016
Suporte XML nativo no SQL Server 2014/2016Suporte XML nativo no SQL Server 2014/2016
Suporte XML nativo no SQL Server 2014/2016
 
Sql Summit Clr, Service Broker And Xml
Sql Summit   Clr, Service Broker And XmlSql Summit   Clr, Service Broker And Xml
Sql Summit Clr, Service Broker And Xml
 
Managing database project with Visual Studio SSDT and TFS
Managing database project with Visual Studio SSDT and TFSManaging database project with Visual Studio SSDT and TFS
Managing database project with Visual Studio SSDT and TFS
 
SSDT unleashed
SSDT unleashedSSDT unleashed
SSDT unleashed
 
SSDT Workshop @ SQL Bits X (2012-03-29)
SSDT Workshop @ SQL Bits X (2012-03-29)SSDT Workshop @ SQL Bits X (2012-03-29)
SSDT Workshop @ SQL Bits X (2012-03-29)
 

Similar to Sql server 2008 r2 xml wp

crystal xcelsius and web services by dashboardcafe.com
crystal xcelsius and web services by dashboardcafe.comcrystal xcelsius and web services by dashboardcafe.com
crystal xcelsius and web services by dashboardcafe.com
Sigit Yunanto
 
Relational data as_xml
Relational data as_xmlRelational data as_xml
Relational data as_xml
Harshavardhan Achrekar
 
Xml Validation Test Suite With Camv
Xml Validation Test Suite With CamvXml Validation Test Suite With Camv
Xml Validation Test Suite With Camv
Bizagi Inc
 
Sql Portfolio
Sql PortfolioSql Portfolio
Sql Portfolio
Shelli Ciaschini
 
Sql2005 xml
Sql2005 xmlSql2005 xml
Sql2005 xmlnkaluva
 
Extending Schemas
Extending SchemasExtending Schemas
Extending SchemasLiquidHub
 
SQLite in Adobe AIR
SQLite in Adobe AIRSQLite in Adobe AIR
SQLite in Adobe AIRPeter Elst
 
XLS PE How To Tutorials Tips & Tricks
XLS PE How To Tutorials Tips & TricksXLS PE How To Tutorials Tips & Tricks
XLS PE How To Tutorials Tips & Tricksguest92a5de
 
XLS Processor Engine How To, Tutorials, Tips & Tricks
XLS Processor Engine How To, Tutorials, Tips & TricksXLS Processor Engine How To, Tutorials, Tips & Tricks
XLS Processor Engine How To, Tutorials, Tips & TricksEarl Grau
 
Oracle Data Redaction
Oracle Data RedactionOracle Data Redaction
Oracle Data Redaction
Alex Zaballa
 
Aug Xml Net Forum Dynamics Integration
Aug Xml Net Forum Dynamics IntegrationAug Xml Net Forum Dynamics Integration
Aug Xml Net Forum Dynamics Integration
MariAnne Woehrle
 
Extending MySQL Enterprise Monitor
Extending MySQL Enterprise MonitorExtending MySQL Enterprise Monitor
Extending MySQL Enterprise Monitor
Mark Leith
 
SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3
SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3
SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3
Dan D'Urso
 
XML Introduction
XML IntroductionXML Introduction
XML Introduction
Marco Bresciani
 
MS Dynamics CRM 2011 Technical
MS Dynamics CRM 2011 TechnicalMS Dynamics CRM 2011 Technical
MS Dynamics CRM 2011 TechnicalAnilCSlides
 
Working With XML in IDS Applications
Working With XML in IDS ApplicationsWorking With XML in IDS Applications
Working With XML in IDS Applications
Keshav Murthy
 

Similar to Sql server 2008 r2 xml wp (20)

Sql2005 Xml
Sql2005 XmlSql2005 Xml
Sql2005 Xml
 
crystal xcelsius and web services by dashboardcafe.com
crystal xcelsius and web services by dashboardcafe.comcrystal xcelsius and web services by dashboardcafe.com
crystal xcelsius and web services by dashboardcafe.com
 
Relational data as_xml
Relational data as_xmlRelational data as_xml
Relational data as_xml
 
Xml Validation Test Suite With Camv
Xml Validation Test Suite With CamvXml Validation Test Suite With Camv
Xml Validation Test Suite With Camv
 
Sql Portfolio
Sql PortfolioSql Portfolio
Sql Portfolio
 
Sql2005 xml
Sql2005 xmlSql2005 xml
Sql2005 xml
 
Extending Schemas
Extending SchemasExtending Schemas
Extending Schemas
 
SQLite in Adobe AIR
SQLite in Adobe AIRSQLite in Adobe AIR
SQLite in Adobe AIR
 
XLS PE How To Tutorials Tips & Tricks
XLS PE How To Tutorials Tips & TricksXLS PE How To Tutorials Tips & Tricks
XLS PE How To Tutorials Tips & Tricks
 
XLS Processor Engine How To, Tutorials, Tips & Tricks
XLS Processor Engine How To, Tutorials, Tips & TricksXLS Processor Engine How To, Tutorials, Tips & Tricks
XLS Processor Engine How To, Tutorials, Tips & Tricks
 
Oracle Data Redaction
Oracle Data RedactionOracle Data Redaction
Oracle Data Redaction
 
treeview
treeviewtreeview
treeview
 
treeview
treeviewtreeview
treeview
 
Aug Xml Net Forum Dynamics Integration
Aug Xml Net Forum Dynamics IntegrationAug Xml Net Forum Dynamics Integration
Aug Xml Net Forum Dynamics Integration
 
Extending MySQL Enterprise Monitor
Extending MySQL Enterprise MonitorExtending MySQL Enterprise Monitor
Extending MySQL Enterprise Monitor
 
SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3
SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3
SQL202.3 Accelerated Introduction to SQL Using SQL Server Module 3
 
XML Introduction
XML IntroductionXML Introduction
XML Introduction
 
Xml Schema
Xml SchemaXml Schema
Xml Schema
 
MS Dynamics CRM 2011 Technical
MS Dynamics CRM 2011 TechnicalMS Dynamics CRM 2011 Technical
MS Dynamics CRM 2011 Technical
 
Working With XML in IDS Applications
Working With XML in IDS ApplicationsWorking With XML in IDS Applications
Working With XML in IDS Applications
 

More from Klaudiia Jacome

Aoutsourcing para capitulo 7
Aoutsourcing para capitulo 7Aoutsourcing para capitulo 7
Aoutsourcing para capitulo 7Klaudiia Jacome
 
Applicationandmulti instances
Applicationandmulti instancesApplicationandmulti instances
Applicationandmulti instancesKlaudiia Jacome
 
Sql server2008 r2_mds_datasheet
Sql server2008 r2_mds_datasheetSql server2008 r2_mds_datasheet
Sql server2008 r2_mds_datasheetKlaudiia Jacome
 
Microsoft sql server 2008 r2 business intelligence
Microsoft sql server 2008 r2 business intelligenceMicrosoft sql server 2008 r2 business intelligence
Microsoft sql server 2008 r2 business intelligenceKlaudiia Jacome
 
Introduction to master data services
Introduction to master data servicesIntroduction to master data services
Introduction to master data servicesKlaudiia Jacome
 
Sql server2008 r2_bi_datasheet_final
Sql server2008 r2_bi_datasheet_finalSql server2008 r2_bi_datasheet_final
Sql server2008 r2_bi_datasheet_finalKlaudiia Jacome
 
Sql server 2008 business intelligence tdm deck
Sql server 2008 business intelligence tdm deckSql server 2008 business intelligence tdm deck
Sql server 2008 business intelligence tdm deckKlaudiia Jacome
 
Microsoft sql server 2008 r2 business intelligence
Microsoft sql server 2008 r2 business intelligenceMicrosoft sql server 2008 r2 business intelligence
Microsoft sql server 2008 r2 business intelligenceKlaudiia Jacome
 

More from Klaudiia Jacome (20)

Aoutsourcing para capitulo 7
Aoutsourcing para capitulo 7Aoutsourcing para capitulo 7
Aoutsourcing para capitulo 7
 
Si las cosas van mal
Si las cosas van malSi las cosas van mal
Si las cosas van mal
 
Analysis services
Analysis  servicesAnalysis  services
Analysis services
 
Enterprise security
Enterprise securityEnterprise security
Enterprise security
 
Performance
PerformancePerformance
Performance
 
Performance
PerformancePerformance
Performance
 
Enterprise security
Enterprise securityEnterprise security
Enterprise security
 
Data warehouse
Data warehouseData warehouse
Data warehouse
 
Managemen tools
Managemen toolsManagemen tools
Managemen tools
 
Managemen tolos
Managemen tolosManagemen tolos
Managemen tolos
 
Datos espaciales
Datos espacialesDatos espaciales
Datos espaciales
 
Data warehouse
Data warehouseData warehouse
Data warehouse
 
Avances analticos
Avances analticosAvances analticos
Avances analticos
 
Applicationandmulti instances
Applicationandmulti instancesApplicationandmulti instances
Applicationandmulti instances
 
Sql server2008 r2_mds_datasheet
Sql server2008 r2_mds_datasheetSql server2008 r2_mds_datasheet
Sql server2008 r2_mds_datasheet
 
Microsoft sql server 2008 r2 business intelligence
Microsoft sql server 2008 r2 business intelligenceMicrosoft sql server 2008 r2 business intelligence
Microsoft sql server 2008 r2 business intelligence
 
Introduction to master data services
Introduction to master data servicesIntroduction to master data services
Introduction to master data services
 
Sql server2008 r2_bi_datasheet_final
Sql server2008 r2_bi_datasheet_finalSql server2008 r2_bi_datasheet_final
Sql server2008 r2_bi_datasheet_final
 
Sql server 2008 business intelligence tdm deck
Sql server 2008 business intelligence tdm deckSql server 2008 business intelligence tdm deck
Sql server 2008 business intelligence tdm deck
 
Microsoft sql server 2008 r2 business intelligence
Microsoft sql server 2008 r2 business intelligenceMicrosoft sql server 2008 r2 business intelligence
Microsoft sql server 2008 r2 business intelligence
 

Recently uploaded

By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 

Recently uploaded (20)

By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 

Sql server 2008 r2 xml wp

  • 1. What’s New for XML in SQL Server 2008?<br />White Paper<br />Published: August 2008<br />Summary: Microsoft® SQL Server™ 2008 builds on the extensive support for XML by extending support for XML schema validation and XQuery, and by enhancing the xml data type.<br />.<br />Contents<br /> TOC quot; 1-2quot; Introduction PAGEREF _Toc205573720 1<br />The Evolution of SQL Server XML Capabilities PAGEREF _Toc205573721 1<br />XML Functionality in SQL Server 2000 PAGEREF _Toc205573722 1<br />XML Functionality in SQL Server 2005 PAGEREF _Toc205573723 2<br />XML Functionality in SQL Server 2008 PAGEREF _Toc205573724 5<br />XML Schema Validation Enhancements PAGEREF _Toc205573725 5<br />Lax Validation Support PAGEREF _Toc205573726 6<br />Full xs:dateTime Support PAGEREF _Toc205573727 7<br />Union and List Types PAGEREF _Toc205573728 8<br />XQuery Enhancements PAGEREF _Toc205573729 10<br />XML DML Enhancements PAGEREF _Toc205573730 11<br />Conclusion PAGEREF _Toc205573731 12<br />Introduction<br />Microsoft introduced XML-related capabilities in Microsoft SQL Server 2000 with the FOR XML and OPENXML Transact-SQL keywords, which enabled developers to write Transact-SQL code to retrieve a query result as a stream of XML, and to shred an XML document into a rowset. These XML capabilities were extended significantly in SQL Server 2005 with the introduction of a native xml data type that supports XSD schema validation, XQuery-based operations, and XML indexing. SQL Server 2008 builds on the XML capabilities of previous releases and provides enhancements to meet the challenges that customers have faced when storing and manipulating XML data in the database.<br />The Evolution of SQL Server XML Capabilities<br />The XML features of SQL Server have evolved with each version of SQL Server since SQL Server 2000. Before we examine the enhancements in SQL Server 2008, it might be useful to chart the evolution of XML functionality through the previous versions.<br />XML Functionality in SQL Server 2000<br />In SQL Server 2000, Microsoft introduced the FOR XML and OPENXML Transact-SQL keywords. FOR XML is an extension to the SELECT statement that returns the query results as a stream of XML as shown in the following example.<br />SELECT ProductID, ProductName<br />FROM Products Product<br />FOR XML AUTO<br />This query returns an XML fragment like the following example.<br /><Product ProductID=quot; 1quot; ProductName=quot; Widgetquot; /><br /><Product ProductID=quot; 2quot; ProductName=quot; Sprocketquot; /><br />The OPENXML function performs the opposite function to the FOR XML clause by creating a rowset from an XML document, as shown in the following example.<br />DECLARE @doc nvarchar(1000)<br />SET @doc = '<Order OrderID = quot; 1011quot; ><br /><Item ProductID=quot; 1quot; Quantity=quot; 2quot; /><br /><Item ProductID=quot; 2quot; Quantity=quot; 1quot; /><br /></Order>'<br />DECLARE @xmlDoc integer<br />EXEC sp_xml_preparedocument @xmlDoc OUTPUT, @doc<br />SELECT * FROM<br />OPENXML (@xmlDoc, 'Order/Item', 1)<br />WITH<br />(OrderID integer '../@OrderID',<br /> ProductID integer,<br /> Quantity integer)<br />EXEC sp_xml_removedocument @xmlDoc<br />Note the use of the sp_xml_preparedocument and sp_xml_removedocument stored procedures to create an in-memory representation of the node tree for the XML document. This Transact-SQL code returns the following rowset.<br />OrderIDProductIDQuantity101112101121<br />XML Functionality in SQL Server 2005<br />In SQL Server 2005, the FOR XML feature was enhanced with new options for root elements and element names, the ability to nest FOR XML calls so you can build complex hierarchies, and a new PATH mode that enables you to define the structure of the XML to be retrieved by using XPath syntax, as shown in the following example.<br />SELECT ProductID AS '@ProductID',<br />ProductName AS 'ProductName'<br />FROM Products<br />FOR XML PATH ('Product'), ROOT ('Products')<br />This query returns the following XML.<br /><Products><br /><Product ProductID=quot; 1quot; ><br /><ProductName>Widget</ProductName><br /></Product><br /><Product ProductID=quot; 2quot; ><br /><ProductName>Sprocket</ProductName><br /></Product><br /></Products><br />In addition to enhancing the existing XML features that had been introduced in SQL Server 2000, SQL Server 2005 added a new, native xml data type that enables you to create variables and columns for XML data, as shown in the following example.<br />CREATE TABLE SalesOrders<br />(OrderID integer PRIMARY KEY,<br /> OrderDate datetime,<br /> CustomerID integer,<br /> OrderNotes xml)<br />You can use the xml data type to store markup documents or semi-structured data in the database. Columns and variables can be used for untyped XML or typed XML, the latter of which is validated against an XML Schema Definition (XSD) schema. To define the schemas for data validation, developers can use the CREATE XML SCHEMA COLLECTION statement, as shown in the following example.<br />CREATE XML SCHEMA COLLECTION ProductSchema AS<br />'<?xml version=quot; 1.0quot; encoding=quot; UTF-16quot; ?><br /><xs:schema xmlns:xs=quot; http://www.w3.org/2001/XMLSchemaquot; ><br /> <!-- schema declarations go here --><br /></xs:schema>'<br />After creating a schema collection, you can associate an xml variable or column with the schema declarations it contains by referencing the schema collection as shown in the following example.<br />CREATE TABLE SalesOrders<br />(OrderID integer PRIMARY KEY,<br /> OrderDate datetime,<br /> CustomerID integer,<br /> OrderNotes xml(ProductSchema))<br />Typed XML is validated against the declarations in the associated schema collection when values are inserted or updated, which makes it possible to enforce business rules about the structure of XML data for compliance or compatibility reasons.<br />The xml data type also provides a number of methods, which you can use to query and manipulate the XML data in an instance. For example, you can use the query method to query the XML in an instance of the xml data type, as shown in the following example.<br />declare @x xml<br />set @x=<br />'<Invoices><br /><Invoice><br /><Customer>Kim Abercrombie</Customer><br /><Items><br /><Item ProductID=quot; 2quot; Price=quot; 1.99quot; Quantity=quot; 1quot; /><br /><Item ProductID=quot; 3quot; Price=quot; 2.99quot; Quantity=quot; 2quot; /><br /><Item ProductID=quot; 5quot; Price=quot; 1.99quot; Quantity=quot; 1quot; /><br /></Items><br /></Invoice><br /><Invoice><br /><Customer>Margaret Smith</Customer><br /><Items><br /><Item ProductID=quot; 2quot; Price=quot; 1.99quot; Quantity=quot; 1quot; /><br /></Items><br /></Invoice><br /></Invoices>'<br />SELECT @x.query(<br />'<CustomerList><br />{<br />for $invoice in /Invoices/Invoice<br />return $invoice/Customer<br />}<br /></CustomerList>')<br />The query in this example uses an XQuery expression that finds each Invoice element in the document and returns an XML document that contains the Customer element from each Invoice element, as shown in the following example.<br /><CustomerList><br /> <Customer>Kim Abercrombie</Customer><br /> <Customer>Margaret Smith</Customer><br /></CustomerList><br />Another significant XML-related feature that was introduced in SQL Server 2005 is support for XML indexes. You can create primary and secondary XML indexes for columns of type xml to enhance XML query performance. A primary XML index is a shredded representation of all of the nodes in an XML instance, which the query processor can use to quickly find nodes within an XML value. After you have created a primary XML index, you can create secondary XML indexes to improve the performance of specific types of query. The following example creates a primary XML index, and a secondary XML index of type PATH, which can improve performance of queries that use XPath expressions to identify nodes in an XML instance.<br />CREATE PRIMARY XML INDEX idx_xml_Notes<br />ON SalesOrders (Notes)<br />GO<br />CREATE XML INDEX idx_xml_Path_Notes<br />ON SalesOrders (Notes)<br />USING XML INDEX idx_xml_Notes<br />FOR PATH<br />GO<br />XML Functionality in SQL Server 2008<br />The XML functionality that was introduced in SQL Server 2000 and SQL Server 2005 has been enhanced in SQL Server 2008. Key XML-related enhancements in SQL Server 2008 include:<br />Improved schema validation capabilities<br />Enhancements to XQuery support<br />Enhanced functionality for performing XML data manipulation language (DML) insertions<br />The rest of this whitepaper examines these enhancements and demonstrates how you can use them to implement better XML solutions in SQL Server 2008.<br />XML Schema Validation Enhancements<br />You can validate XML data by enforcing compliance with one or several XSD schemas. A schema defines the permissible XML elements and attributes for a particular XML data structure, and is often used to ensure that XML documents contain all of the required data elements in the correct structure.<br />SQL Server 2005 introduced validation of XML data through the use of XML schema collections. The general approach is to a create schema collection that contains the schema rules for your XML data by using the CREATE XML SCHEMA COLLECTION statement, and then to reference the schema collection name when you define an xml column or variable that must conform to the schema rules in the schema collection. SQL Server then validates any data that is inserted or updated in the column or variable against the schema declarations in the schema collection.<br />XML Schema support in SQL Server 2005 implemented a broad subset of the full XML Schema specification, and covered the most common XML validation scenarios. SQL Server 2008 extends that support to include the following additional schema validation requirements that have been identified by customers:<br />Support for lax validation<br />Full support for dateTime, time and date validation, including preservation of time zone information<br />Improved Support for union and list types<br />Lax Validation Support<br />XML Schemas support wildcard sections in XML documents through the any, anyAttribute, and anyType declarations. For example, consider the following XML schema declaration.<br /><xs:complexType name=quot; Orderquot; mixed=quot; truequot; ><br /> <xs:sequence><br /> <xs:element name=quot; CustomerNamequot; /><br /> <xs:element name=quot; OrderTotalquot; /><br /> <xs:any namespace=quot; ##otherquot; processContents=quot; skipquot; <br />minOccurs=quot; 0quot; maxOccurs=quot; unboundedquot; /><br /> </xs:sequence><br /></xs:complexType><br />This schema declaration defines an XML element named Order, which must contain sub-elements named CustomerName and OrderTotal. Additionally, the element can contain an unlimited number of other elements that belong to a different namespace than the one to which the Order type belongs. The following XML shows an XML document that contains an instance of an Order element as defined by this schema declaration. Note that the order also contains a shp:Delivery element, which is not explicitly defined in the schema.<br /><Invoice xmlns=quot; http://adventure-works.com/orderquot; <br />xmlns:shp=quot; http://adventure-works.com/shippingquot; ><br /> <Order><br /> <CustomerName>Graeme Malcolm</CustomerName><br /> <OrderTotal>299.99</OrderTotal><br /> <shp:Delivery>Express</shp:Delivery><br /> </Order><br /></Invoice><br />Validation for wildcard sections depends on the processContents attribute for the wildcard section in the schema definition. In SQL Server 2005, schemas can use processContents values of skip and strict for any and anyAttribute declarations. In the previous example, the processContents attribute for the wildcard element has been set to skip, so no attempt to validate the contents of that element is made. Even if the schema collection includes a declaration for the shp:Delivery element (for example, defining a list of valid delivery methods), the element is not validated unless the declaration for the wildcard in the Order element has its processContents attribute set to strict.<br />SQL Server 2008 adds support for a third validation option. By setting the processContents attribute for a wildcard section to lax, you can enforce validation for any elements that have schema declarations associated with them, but ignore any elements that are not defined in the schema. To continue the previous example, if you set the processContents attribute for the wildcard element declaration in the schema to lax and add a declaration for the shp:Delivery element, shp:Delivery element in the XML document is validated. However, if instead of the shp:Delivery element, the document includes an element that is not defined in the schema, the element is ignored.<br />In addition, the XML Schema specification defines that the anyType declaration has lax processing of its content model. SQL Server 2005 does not support lax processing, so the content is validated strictly instead. SQL Server 2008 does support lax processing of the anyType contents, and so the content is validated correctly.<br />Full xs:dateTime Support<br />You can use the dateTime data type in an XML schema to define date and time data. Date and time data is expressed in the format 2007-08-01T09:30:00:000Z, which represents the 1st of August 2007 at 9:30 in the morning in the coordinated universal time zone (UTC), which is indicated by the Z. Other time zones are represented by the time difference from UTC, so for example you can represent 6:00 in the morning on December 25th 2007 in Pacific Standard Time (which is 8 hours behind UTC) with the value 2007-12-25T06:00:00:000-8:00.<br />The XML Schema specification defines the time zone component of the dateTime, date and time data types as optional. However, in SQL Server 2005 you must provide a time zone for dateTime, time and date data. Additionally, SQL Server 2005 does not preserve the time zone information for your data for dateTime or time, but normalizes it to UTC (so for example, if your XML contains the value 2007-12-25T06:00:00:000-8:00, SQL Server 2005 normalizes this as 2007-12-25T14:00:00:000Z.) In SQL Server 2008, these limitations have been removed, so you can omit the time zone information when you store dateTime, date or time data, and any time zone information that you do provide is preserved.<br />Union and List Types<br />You can use XML schemas to define data types for your XML data that allow a limited set of values to be assigned to multi-value elements and attributes. For example, you might define a sizeListType type that restricts the list of possible values that can be assigned to an AvaliableSizes element in the product definition to S, M, and L. SQL Server 2005 supports XML schemas that contain these simple type definitions and restrictions. For example, you can use a list type to define the valid sizes for a product as shown in the following example.<br /><xs:simpleType name=quot; sizeListTypequot; ><br /> <xs:list><br /> <xs:simpleType><br /> <xs:restriction base=quot; xs:stringquot; ><br /> <xs:enumeration value=quot; Squot; /><br /> <xs:enumeration value=quot; Mquot; /><br /> <xs:enumeration value=quot; Lquot; /><br /> </xs:restriction><br /> </xs:simpleType><br /> </xs:list><br /></xs:simpleType><br />This schema declaration enables you to create an element that lists all of the sizes in which a product can be purchased as a list of values separated by white space, as shown in the following example:<br /><AvailableSizes>S M L</AvailableSizes><br />However, what if you want to support two different ways to express the size of a product? For example, suppose a cycling equipment retailer sells cycling clothes in small, medium, and large sizes, but also sells bicycles in numerical sizes relating to the frame size (such as 18, 20, 22, and 24)? To enable you to accomplish this, SQL Server 2008 adds support for union types that contain list types, which you can use to merge multiple list type definitions and restrictions into a single type. For example, the following Transact-SQL code creates an XML schema collection that defines a productSizeType type in which valid values include a list of numeric sizes (18, 20, 22, and 24) and a list of named sizes (S, M, and L).<br />CREATE XML SCHEMA COLLECTION CatalogSizeSchema AS<br />N'<?xml version=quot; 1.0quot; encoding=quot; UTF-16quot; ?><br /><xs:schema xmlns:xs=quot; http://www.w3.org/2001/XMLSchemaquot; ><br /><xs:simpleType name=quot; productSizeTypequot; ><br /><xs:union><br /><xs:simpleType><br /> <xs:list><br /><xs:simpleType><br /> <xs:restriction base=quot; xs:integerquot; ><br /><xs:enumeration value=quot; 18quot; /><br /><xs:enumeration value=quot; 20quot; /><br /><xs:enumeration value=quot; 22quot; /><br /><xs:enumeration value=quot; 24quot; /><br /> </xs:restriction><br /></xs:simpleType><br /> </xs:list><br /></xs:simpleType><br /><xs:simpleType><br /> <xs:list><br /><xs:simpleType><br /> <xs:restriction base=quot; xs:stringquot; ><br /><xs:enumeration value=quot; Squot; /><br /><xs:enumeration value=quot; Mquot; /><br /><xs:enumeration value=quot; Lquot; /><br /> </xs:restriction><br /></xs:simpleType><br /> </xs:list><br /></xs:simpleType><br /></xs:union><br /></xs:simpleType><br /></xs:schema>'<br />With this declaration in the schema, any elements based on the productSizeType can contain either kind of list; so both of the product elements in the following example would be valid instances of the productSizeType data type.<br /><Catalog><br /> <Product><br /> <ProductName>Road Bike</ProductName><br /> <AvailableSizes>22 24</AvailableSizes><br /> </Product><br /> <Product><br /> <ProductName>Cycling Jersey</ProductName><br /> <AvailableSizes>S M L</AvailableSizes><br /> </Product><br /></Catalog><br />Similarly, SQL Server 2008 supports schema declarations for list types that contain union types.<br />XQuery Enhancements<br />SQL Server 2005 introduced the xml data type, which provides a number of methods that you can use to perform operations on the XML data stored in a column or variable. Most of the operations you can perform use XQuery syntax to navigate and manipulate the XML data. The XQuery syntax supported by SQL Server 2005 includes the for, where, order by, and return clauses of the so called FLWOR expression, which you can use to iterate over the nodes in an XML document and return values.<br />SQL Server 2008 adds support for the let clause, which is used to assign values to variables in an XQuery expression such as the following example:<br />declare @x xml<br />set @x=<br />'<Invoices><br /><Invoice><br /><Customer>Kim Abercrombie</Customer><br /><Items><br /><Item ProductID=quot; 2quot; Price=quot; 1.99quot; Quantity=quot; 1quot; /><br /><Item ProductID=quot; 3quot; Price=quot; 2.99quot; Quantity=quot; 2quot; /><br /><Item ProductID=quot; 5quot; Price=quot; 1.99quot; Quantity=quot; 1quot; /><br /></Items><br /></Invoice><br /><Invoice><br /><Customer>Margaret Smith</Customer><br /><Items><br /><Item ProductID=quot; 2quot; Price=quot; 1.99quot; Quantity=quot; 1quot; /><br /></Items><br /></Invoice><br /></Invoices>'<br />SELECT @x.query(<br />'<Orders><br />{<br />for $invoice in /Invoices/Invoice<br />let $count :=count($invoice/Items/Item)<br />order by $count<br />return<br /><Order><br />{$invoice/Customer}<br /><ItemCount>{$count}</ItemCount><br /></Order><br />}<br /></Orders>')<br />This example returns the following XML.<br /><Orders><br /><Order><br /><Customer>Margaret Smith</Customer><br /><ItemCount>1</ItemCount><br /></Order><br /><Order><br /><Customer>Kim Abercrombie</Customer><br /><ItemCount>3</ItemCount><br /></Order><br /></Orders><br />Note that SQL Server 2008 does not allow the assignment of constructed elements.<br />XML DML Enhancements<br />As well as being able to use XQuery expressions to perform operations on XML data, the xml data type supports the XML DML expressions insert, replace value of, and delete through its modify method. You can use these XML DML expressions to manipulate the XML data in an xml column or variable.<br />SQL Server 2008 adds support for using an xml variable in an insert expression to insert XML data into an existing XML structure. For example, suppose an xml variable named @productList contains the following XML:<br /><Products><br /> <Bike>Mountain Bike</Bike><br /> <Bike>Road Bike</Bike><br /></Products><br />You could use the following code to insert a new bike into the product list:<br />DECLARE @newBike xml<br />SET @newBike = '<Bike>Racing Bike</Bike>'<br />SET @productList.modify<br />('insert sql:variable(quot; @newBikequot; ) as last into (/Products)[1]')<br />After running this code, the @productList variable would contain the following XML.<br /><Products><br /> <Bike>Mountain Bike</Bike><br /> <Bike>Road Bike</Bike><br /> <Bike>Racing Bike</Bike><br /></Products><br />Conclusion<br />SQL Server 2008 builds on the already comprehensive support for XML that was present in SQL Server 2005, and extends your ability to build powerful database solutions that combine relational data and XML. The improvements to XML schema support, as well as the enhancements to the xml data type provide benefits that application developers will find immensely appealing.<br />For more information:<br />http://www.microsoft.com/sql/<br />Please give us your feedback:<br />Did this paper help you? Tell us on a scale of 1 (poor) to 5 (excellent), how would you rate this paper and why have you given it this rating? For example:<br />Are you giving it a high rating because it has good examples, excellent screenshots, clear writing, or another reason? <br />Are you giving it a low rating because it has poor examples, fuzzy screenshots, unclear writing?<br />This feedback will help us improve the quality of white papers we release. Send feedback.<br />