有人可以解释我是否可以从互联网上读取xml页面并将其从mssql中导入多个原始数据库表?
我有一个名为的页面:
https://mywebsite.com/api/?u=xxxxxxx&p=yyyyyy&fields=CallerID&format=xml
这将给我以下信息:
This XML file does not appear to have any style information associated with it. The document tree is shown below
<records>
<call>
<callingnumber>357994</callingnumber>
</call>
<call>
<callingnumber>357996</callingnumber>
</call>
<call>
<callingnumber>357995</callingnumber>
</call>
</records>
事情是这个内容无法在服务器内部以xml的形式下载。所以mssql必须在线阅读文件。
我尝试使用以下代码,但它出现错误:
DECLARE @x XML
SELECT @x = cast(x.bulkColumn as XML)
FROM OPENROWSET(BULK 'https://mywebsite.com/api/?u=xxxxxxx&p=yyyyyy&fields=CallerID&format=xml', SINGLE_CLOB) AS x
select @x;
错误是:
Cannot bulk load because the file "https://mywebsite.com/api/?u=xxxxxxx&p=yyyyyy&fields=CallerID&format=xml" could not be opened. Operating system error code 123(The filename, directory name, or volume label syntax is incorrect.).
任何人都可以帮我解决这个问题。
此致
答案 0 :(得分:0)
我已经找到了一个如何以简单的方式做到这一点的答案。 您可以创建一个powershell脚本并将其命名为ex。 script.ps1
[xml]$x = (New-Object System.Net.WebClient).DownloadString("https://yourwebsite.com/api/?u=xxxxxx&p=xxxxxx&format=xml")
$x.Save(‘C:\folder\name.xml’);
从存储过程运行脚本:
exec master..xp_cmdshell 'powershell -ExecutionPolicy ByPass -File c:\script.ps1'