我需要从数据库中提取数据并通过 ssis 创建一个 xml 文件。到目前为止,我已经创建了一个脚本,可以成功创建一个 xml 文件(使用 XmlTextWriter),列出所有必要的数据,但是,他们也希望在文件中列出架构,我不知道该怎么做。
这是我当前创建 xml 文件的代码(在我的数据流中使用脚本组件):
StreamWriter sw; XmlTextWriter xWriter; String rowName; String collectionName; private int[] columnNames;
public override void PreExecute()
{
rowName = "Responses";
collectionName = "NewDataSet";
String fileName = Variables.FullFileName;
xWriter = new XmlTextWriter(fileName, null);
xWriter.WriteStartDocument();
xWriter.WriteStartElement(collectionName);
}
public override void PostExecute()
{
xWriter.WriteEndElement();
xWriter.WriteEndDocument();
xWriter.Close();
}
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
Type rowType = Row.GetType();
PropertyInfo columnValue;
xWriter.WriteStartElement(rowName);
foreach (IDTSInputColumn100 column in this.ComponentMetaData.InputCollection[0].InputColumnCollection)
{
columnValue = rowType.GetProperty(column.Name);
xWriter.WriteStartElement(column.Name);
Object value = columnValue.GetValue(Row, null);
if(value != null)
{
xWriter.WriteValue(value.ToString());
}
xWriter.WriteEndElement();
}
}
如何向其中添加架构信息?我看过“WriteXmlSchema”的教程,但这似乎只适用于数据集(我没有使用)。
我非常感谢您能提供的任何帮助。