SSIS Script Transform to Shred XML data

  • I have a process where I am querying a database that has an NTEXT column that contains XML (should be valid XML). In my data flow I need to shred the XML to get about 5 values to add as columns to the data flow. Here's what I'm attempting:

    System.Text.UnicodeEncoding encoding= new System.Text.

    byte[] bytes = Row.XMLData.GetBlobData(0, (int)Row.XMLData.Length);

    System.Xml.Linq.XDocument xDoc = Xdocument.Load(encoding.GetString(bytes));

    Row.PolicyNumber = xDoc.Element("ElementName").Value;

    I'm getting an error when trying to load the xDoc. The error is "invalid uri the uri string is too long" and I'm not finding any good answers in Binoogle.

    So is there a better way?

  • Okay, I'm not that smart. I have the answer. Here's the new code:

    System.Text.UnicodeEncoding encoding= new System.Text.

    byte[] bytes = Row.XMLData.GetBlobData(0, (int)Row.XMLData.Length);

    StringReader sr = new StringReader(encoding.GetString(bytes));

    System.Xml.Linq.XDocument xDoc= Xdocument.Load(sr);

    XNamespace xNs = xDoc.Root.Name.Namespace;

    var xdata = (from policy in xDoc.Descendants(xNs + "data").Descendants(xNs + "policy")

    select new

    {

    policyNumber = policy.Element(xNs + "PolicyNumbersJustPolicyNumber").Value

    }).SingleOrDefault();

    I was trying to load a document not a stream.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply