使用SQL Server连接xml接口,读取并解析数据
生活随笔
收集整理的這篇文章主要介紹了
使用SQL Server连接xml接口,读取并解析数据
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?
--數據源格式,放到任意程序中部署接口即可--<Data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> --<Peoples> --<People> --<Name>張三</Name> --<Sex>男</Sex> --</People> --<People> --<Name>李四</Name> --<Sex>女</Sex> --</People> --<People> --<Name>王武</Name> --<Sex>男</Sex> --</People> --<People> --<Name>趙柳</Name> --<Sex>女</Sex> --</People> --<People> --<Name>武士刀</Name> --<Sex>男</Sex> --</People> --</Peoples> --</Data>--調用webService----------------declare @ServiceUrl as varchar(1000) DECLARE @UrlAddress varchar(500)--WebService地址:以http開頭,結尾帶斜杠,例如'https://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx/' set @UrlAddress = 'http://localhost:11687/home/webxml'SET @ServiceUrl=@UrlAddress--如果有參數可以在此處拼入--訪問地址獲取結果Declare @Object as IntDeclare @ResponseText as Varchar(8000) --必須8000Declare @Data as XML EXEC sp_OACreate 'MSXML2.XMLHTTP', @Object OUT; --創建OLE組件對象Exec sp_OAMethod @Object, 'open', NULL, 'POST',@ServiceUrl,'false' --打開鏈接,注意是get還是postExec sp_OAMethod @Object, 'send'EXEC sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT --輸出參數Select @ResponseText --輸出結果SET @Data = CAST(@ResponseText AS XML)select t.c.value('(Name/text())[1]','VARCHAR(20)') as Name,t.c.value('(Sex/text())[1]','VARCHAR(20)') as Sexfrom @Data.nodes('/*/*/*') as t(c)Exec sp_OADestroy @ObjectGO----開啟 Ole Automation Procedures --sp_configure 'show advanced options', 1; --GO --RECONFIGURE; --GO --sp_configure 'Ole Automation Procedures', 1; --GO --RECONFIGURE; --GO --EXEC sp_configure 'Ole Automation Procedures'; --GO----關閉 Ole Automation Procedures --sp_configure 'show advanced options', 0; --GO --RECONFIGURE; --GO --sp_configure 'Ole Automation Procedures', 0; --GO --RECONFIGURE; --GO --EXEC sp_configure 'Ole Automation Procedures'; --GO
----開啟Ad Hoc Distributed Queries組件,在sql查詢編輯器中執行如下語句: --exec sp_configure 'show advanced options',1 --reconfigure --exec sp_configure 'Ad Hoc Distributed Queries',1 --reconfigure ----關閉Ad Hoc Distributed Queries組件,在sql查詢編輯器中執行如下語句: --exec sp_configure 'Ad Hoc Distributed Queries',0 --reconfigure --exec sp_configure 'show advanced options',0 --reconfigure
?
??
轉載于:https://www.cnblogs.com/GoCircle/p/9401188.html
總結
以上是生活随笔為你收集整理的使用SQL Server连接xml接口,读取并解析数据的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 1分钟入门接口自动化框架Karate
- 下一篇: 关于Mysql java.sql.SQL