用 query 方法 獲得xml 節點的值,queryxml

來源:互聯網
上載者:User

用 query 方法 獲得xml 節點的值,queryxml

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

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.