日期:2014-05-17 浏览次数:21047 次
declare @x xml = N'<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="SID" >
<xs:restriction base="xs:string">
<xs:maxLength value="85" />
</xs:restriction>
</xs:simpleType>
</xs:schema>'
-- 1. with xmlnamespaces
;with xmlnamespaces('http://www.w3.org/2001/XMLSchema' as xs)
select @x.query('data(//xs:maxLength/@value)')
-- 2 declare namespaces in XQuery
select @x.query('
declare default element namespace "http://www.w3.org/2001/XMLSchema";
data(//maxLength/@value)
')
/*
XML Data Modification Language (XML DML)
http://msdn.microsoft.com/en-us/library/ms177454.aspx
XQuery Language Reference (SQL Server)
http://msdn.microsoft.com/en-us/library/ms189075.aspx
*/