I want to get a data from a web XML URL and convert the result to a standard table with the values.
I have the following code:
IF OBJECT_ID('tempdb..#xml') IS NOT NULL
DROP TABLE #xml
CREATE TABLE #xml (yourXML XML)
GO
DECLARE @URL NVARCHAR(max)
SELECT @URL = 'https://www.boi.org.il/currency.xml'
DECLARE @Response varchar(8000)
DECLARE @XML xml
DECLARE @Obj int
DECLARE @Result int
DECLARE @HTTPStatus int
DECLARE @ErrorMsg varchar(MAX)
EXEC @Result = sp_OACreate 'MSXML2.XMLHttp', @Obj OUT
EXEC @Result = sp_OAMethod @Obj, 'open', NULL, 'GET', @URL, false
EXEC @Result = sp_OAMethod @Obj, 'setRequestHeader', NULL, 'Content-Type', 'application/x-www-form-urlencoded'
EXEC @Result = sp_OAMethod @Obj, send, NULL, ''
EXEC @Result = sp_OAGetProperty @Obj, 'status', @HTTPStatus OUT
INSERT #xml ( yourXML )
EXEC @Result = sp_OAGetProperty @Obj, 'responseXML.xml'--, @Response OUT
SELECT x.*, y.c.query('.')
FROM #xml x
CROSS APPLY x.yourXML.nodes('/CURRENCIES/CURRENCY') y(c)
Right now the result of this code is a XML "hyperlink" query and I would like to get it as a standard values query result that in the end I can work with the data.
The query result structure columns should be:
LAST_UPDATE | NAME | UNIT | CURRENCYCODE | RATE