加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

用 query 方法 获得xml 节点的值

发布时间:2020-12-16 06:14:27 所属栏目:百科 来源:网络整理
导读: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.ServiceWe
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 方法中声明这些命名空间。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读