在 SSIS 脚本任务中将 XML 数据从 URL 写入对象
我有这个包含 XML 数据的 URL。我必须从 URL 中提取该数据并将其转储到 DW 表中。我正在为此使用 SSIS 脚本任务。
数据如下所示:
-
<csymbol>AED</csymbol>
<cname>United Arab Emirates Dirhams</cname>
<crate>3.6732001305</crate>
<cinverse>0.2722421770</cinverse>
−
<csymbol>AFN</csymbol>
<cname>Afghanistan Afghanis</cname>
<crate>44.0000000000</crate>
<cinverse>0.0227272727</cinverse>
−
<csymbol>ALL</csymbol>
<cname>Albania Leke</cname>
<crate>104.4100000001</crate>
<cinverse>0.0095776267</cinverse>
这是我用来将其加载到某些对象类型或其他内容中的代码。但我不知道该怎么做。
public void Main()
{
String URLString = "http://www.xe.com/dfs/datafeed2.cgi?beeline";
XmlDocument doc = new XmlDocument();
XmlTextReader reader = new XmlTextReader(URLString);
doc.Load(reader);
XmlNodeList currencynodes = doc.SelectNodes("currency");
foreach(XmlNode currency in currencynodes)
{
XmlNode csymbol = currency.SelectSingleNode("csymbol");
string csymbolvalue = csymbol.Value;
XmlNode cname = currency.SelectSingleNode("cname");
string cnamevalue = cname.Value;
XmlNode crate = currency.SelectSingleNode("crate");
string cratevalue = crate.Value;
XmlNode cinverse = currency.SelectSingleNode("cinverse");
string cinversevalue = cinverse.Value;
Dts.Variables["User::oCurrencyConversion"].Value = csymbol.Value;
}
I have this URL where there is XML data. I have to extract that data from URL and dump it into DW table. I am using SSIS Script Task for that.
This is how the data looks like:
-<currency>
<csymbol>AED</csymbol>
<cname>United Arab Emirates Dirhams</cname>
<crate>3.6732001305</crate>
<cinverse>0.2722421770</cinverse>
</currency>
−<currency>
<csymbol>AFN</csymbol>
<cname>Afghanistan Afghanis</cname>
<crate>44.0000000000</crate>
<cinverse>0.0227272727</cinverse>
</currency>
−<currency>
<csymbol>ALL</csymbol>
<cname>Albania Leke</cname>
<crate>104.4100000001</crate>
<cinverse>0.0095776267</cinverse>
</currency>
This is the code i'm using to load it into some Object type or something. But i dont know how to do that.
public void Main()
{
String URLString = "http://www.xe.com/dfs/datafeed2.cgi?beeline";
XmlDocument doc = new XmlDocument();
XmlTextReader reader = new XmlTextReader(URLString);
doc.Load(reader);
XmlNodeList currencynodes = doc.SelectNodes("currency");
foreach(XmlNode currency in currencynodes)
{
XmlNode csymbol = currency.SelectSingleNode("csymbol");
string csymbolvalue = csymbol.Value;
XmlNode cname = currency.SelectSingleNode("cname");
string cnamevalue = cname.Value;
XmlNode crate = currency.SelectSingleNode("crate");
string cratevalue = crate.Value;
XmlNode cinverse = currency.SelectSingleNode("cinverse");
string cinversevalue = cinverse.Value;
Dts.Variables["User::oCurrencyConversion"].Value = csymbol.Value;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为此,您实际上需要在数据流任务内部使用脚本源组件。然后使用标准目标组件插入 DW。
这是我实现的示例包。 http://dl.dropbox.com/u/5332312/xRateLoader.zip
You actually need to use a Script Source Component inside of a dataflow task for this. Then use the standard destination compoents to do the insert into DW.
Here is a sample package i implemented. http://dl.dropbox.com/u/5332312/xRateLoader.zip
有一次我做了同样的事情,通过 SSIS 包将数据从 XLM 提取到 SQL。
这是基本步骤。
您需要注意VXD是正确的格式,以便SSIS可以预先读取数据。
在我办公室桌面的某个地方,我仍然有该 SSIS 包的源代码,早上第一件事我将尝试找到它并在此处共享。
另外,如果您的 XML 源是公开的,请在此处发布,以便我们尝试为您制作一个。
Aru 您更喜欢使用 C# 或集成服务来完成此任务?
Once I did the same thing pulling data from XLM to SQL trough SSIS package.
Here is basic steps.
You need to pay attention to VXD is right format, so SSIS can read data preply.
Somewhere in my office desktop I still have source of that SSIS Package, first thing in morning I am going to try find that and share here.
Also If is source of your XML is public please post here so we can try make one for you.
Aru You preferred more to do this task usin C# or integration service ?