在 SSIS 脚本任务中将 XML 数据从 URL 写入对象

发布于 2024-09-19 22:19:31 字数 1810 浏览 4 评论 0原文

我有这个包含 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

月亮坠入山谷 2024-09-26 22:19:31

为此,您实际上需要在数据流任务内部使用脚本源组件。然后使用标准目标组件插入 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

微凉徒眸意 2024-09-26 22:19:31

有一次我做了同样的事情,通过 SSIS 包将数据从 XLM 提取到 SQL。

这是基本步骤。

  1. 制作DTS包
  2. 在DataFlow中选择源连接XML并填写关于源和VXD(结构)文件的表格
  3. 然后制作目标连接
  4. 从源到目标拉动绿线

您需要注意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.

  1. Make DTS package
  2. In DataFlow select source connection XML and fill up form abaout source and VXD (structure) file
  3. Then make destination connection
  4. Pull green line from Source to Destination

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 ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文