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; } }