Request XML from URL in SSIS C# Script Task



Occasionally, I’ve needed to pull XML from the internet via an URL. This allows you to dynamically pull XML from sources than your local.In order to do so, you’ll need a string variable (to populate with the XML from the internet) and the code below in a Script Task.

Every time you need to reference the XML in the variable, change your XML Data Sources and XML tasks to pull XML from a variable.

string Url = (string)Dts.Variables["Url"].Value;
XmlDocument doc = new XmlDocument();
doc.Load(Url); //You can use a string here if you’d like…I pull from a variable for the URL
StringWriter sw = new StringWriter();
XmlTextWriter xw = new XmlTextWriter(sw);
doc.WriteTo(xw);
sw.ToString(); Dts.Variables["Xml"].Value = sw.ToString();
Bookmark and Share

Related Information:

  1. SSIS Tip – Read from Variables to Rows in Data Flow using Script Task
    Reading from variables to augment...
  2. SSIS Tip – Xpath from a C# Script Task
    At some point you may...
  3. SSIS Tip – Xpath for Root Level Attributes (XML Tasks)
    For some reason, SSIS’s XML...
  4. SSIS Tip – Save Package to MS SQL Server (Integration Services)
    In order to save your...
  5. Strategy to Create a Usable Multi-function Task List (ADF)
    When People Interact with Executable...

Leave a Reply