1. 程式人生 > >用 query 方法 獲得xml 節點的值

用 query 方法 獲得xml 節點的值

點數據 fun query response code ring select comment received

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 方法中聲明這些命名空間。

用 query 方法 獲得xml 節點的值