SELECT
ProductID, ProductName
FROM
Products Product
FOR
XML AUTO
<
Product
ProductID
=
"1"
ProductName
"Widget"
/>
"2"
"Sprocket"
DECLARE
@doc nvarchar(1000)
SET
@doc =
'<Order OrderID = "1011">
<Item ProductID="1" Quantity="2"/>
<Item ProductID="2" Quantity="1"/>
</Order>'
@xmlDoc
integer
EXEC
sp_XML-preparedocument @xmlDoc
OUTPUT
, @doc
*
OPENXML (@xmlDoc,
'Order/Item'
, 1)
WITH
(OrderID
'../@OrderID'
,
Quantity
)
sp_XML-removedocument @xmlDoc
OrderID ProductID Quantity
1011 1 2
1011 2 1
AS
'@ProductID'
'ProductName'
Products
XML PATH (
'Product'
), ROOT (
'Products'
<Products>
<Product ProductID=
>
<ProductName>Widget</ProductName>
</Product>
<ProductName>Sprocket</ProductName>
</Products>
CREATE
TABLE
SalesOrders
PRIMARY
KEY
OrderDate datetime,
CustomerID
OrderNotes xml)
XML
SCHEMA
COLLECTION ProductSchema
'<?xml version="1.0" encoding="UTF_16"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!- Здесь располагается сама схема ->
</xs:schema>'
OrderNotes xml(ProductSchema))
declare
@x xml
set
@x=
'<Invoices>
<Invoice>
<Customer>Kim Abercrombie</Customer>
<Items>
<Item ProductID="2" Price="1.99" Quantity="1" />
<Item ProductID="3" Price="2.99" Quantity="2" />
<Item ProductID="5" Price="1.99" Quantity="1" />
</Items>
</Invoice>
<Customer>Margaret Smith</Customer>
<Item ProductID="2" Price="1.99" Quantity="1"/>
</Invoices>'
@x.query(
'<CustomerList>
{
for $invoice in /Invoices/Invoice
return $invoice/Customer
}
</CustomerList>'
CustomerList
Customer
>Kim Abercrombie</
>Margaret Smith</
</
INDEX
idx_XML-Notes
ON
SalesOrders (Notes)
GO
idx_XML-Path_Notes
USING XML
PATH
xs:complexType
name
"Order"
mixed
"true"
xs:sequence
xs:element
"CustomerName"
"OrderTotal"
xs:any
namespace
"##other"
processContents
"skip"
minOccurs
"0"
maxOccurs
"unbounded"
Invoice
xmlns
"http://adventure_works.com/order"
xmlns:shp
"http://adventure_works.com/shipping"
Order
CustomerName
>Graeme Malcolm</
OrderTotal
>299.99</
shp:Delivery
>Express</
xs:simpleType
"sizeListType"
xs:list
xs:restriction
base
"xs:string"
xs:enumeration
value
"S"
"M"
"L"
AvailableSizes
>S M L</