Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

Using XmlTextWriter in a Script Component

$
0
0

I am using a Script Component (as a destination) to create an XML output file. I am trying to write the following element to the file:

<PDFCACOBeneData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />

The code I am using is below, however when I run the package, I receive the following error:

"Token StartElement in state Epilog would result in an invalid XML document."

If I combine the code from PreExecute and PostExecute this will work fine. There is something about breaking the code up that is causing the error. 

Anyone have any ideas?

using System;
using System.Xml;        
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;

[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{
    XmlTextWriter textWriter;

    public override void PreExecute()
    {
        base.PreExecute();

        textWriter = new XmlTextWriter(this.Connections.xmldocument.ConnectionString.ToString(), System.Text.Encoding.UTF8);
        textWriter.Formatting = Formatting.Indented;

        textWriter.WriteStartDocument();

        const string ns = "http://www.w3.org/2001/XMLSchema-instance";

        textWriter.WriteStartElement("PDFCACOBeneData");
        textWriter.WriteAttributeString("xmlns", "xsi", null, ns);
        textWriter.WriteEndElement();
        textWriter.WriteStartElement("Beneficiaries");

        return;
    }
    
    public override void PostExecute()
    {
        base.PostExecute();

        textWriter.WriteEndElement();

        textWriter.WriteEndDocument();
        
        textWriter.Flush();
        textWriter.Close();

        return;
    }
    
    public override void Input0_ProcessInputRow(Input0Buffer Row)
    {
	// Code here writes multiple records to the file.
		
        return;
    }

}


Viewing all articles
Browse latest Browse all 24688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>