DECLARE @result xml
SET @result='<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><ReceiveDataResponse xmlns="http://tempuri.org/"><ReceiveDataResult xmlns:a="http://schemas.datacontract.org/2004/07/Cenvation.ServiceWebsite.Datamodel" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><a:ID>17953736-852b-e511-80cc-0050568e38e0</a:ID><a:Message i:nil="true"/><a:SchemaName>contact</a:SchemaName><a:Success>true</a:Success></ReceiveDataResult></ReceiveDataResponse></s:Body></s:Envelope>'
SELECT @result.query('declare namespace s="http://schemas.xmlsoap.org/soap/envelope/";
declare namespace a="http://schemas.datacontract.org/2004/07/Cenvation.ServiceWebsite.Datamodel";
declare namespace i="http://www.w3.org/2001/XMLSchema-instance";
declare default element namespace "http://tempuri.org/"; data(/s:Envelope/s:Body/ReceiveDataResponse/ReceiveDataResult/a:ID)')
這是一個讀取xml 中指定節點數據的一段腳本,這個示例數據中包含命名空間,所以在query 方法中需要聲明這些命名空間,否則無法正確解析這段xml, 如果xml 數據中包含命名空間,就可以不用在query 方法中聲明這些命名空間。