【问题标题】:Fill XML file with SSIS使用 SSIS 填充 XML 文件
【发布时间】:2011-10-10 13:12:31
【问题描述】:

在以下blog 的帮助下:我创建了一个 SQL Server Integration Services (SSIS) 包。从 .txt 文件中读取,我可以创建一个相对 XML 文件并将其保存在特定路径中。

但是,由于我必须循环超过 50 个或更多 txt 文件并为每个文件生成一个相对的 xml 文件,我希望能够自动保存具有相同输入名称的 xml 文件。

我已经看到使用 foreach 循环可以将“.txt”设置为输入文件,但是如何指定动态获取 xml 输出文件的输入文件名?
目前,我为用于设置输出 xml 文件路径的文件连接管理器使用硬编码路径。

此外,是否可以创建 XML 模板并使用 SSIS 相应地填充特定的 关键字,而不是通过 VB 脚本创建 xml 文件?
类似:

<root>
  <product>
      <name>[Prod_Name]</name>
      <qty>[Prod_Qty]</qty>
  </product>
</root>

【问题讨论】:

    标签: xml ssis


    【解决方案1】:

    在脚本任务中使用 System.IO.Path.GetFileNameWithoutExtension:

    Public Sub Main()
        Dim infile As String = CStr(Dts.Variables("InputFile").Value)
        Dim outfile As String = System.IO.Path.GetFileNameWithoutExtension(infile) + ".xml"
        Dts.Variables("OutputFile").Value = outfile
        Dts.TaskResult = ScriptResults.Success
    End Sub
    

    【讨论】:

    • +1 - 我最终使用 With xmlWriter 编写了 xml 标签,并且能够获得相同的结果。不过谢谢你的提示。
    【解决方案2】:

    我在这里发布我的解决方案,以防它可能对其他人有所帮助。 正如评论中所说,我使用脚本转换来根据需要动态创建 xml 标签:

    With xmlWriter            
     .Write(FormatElement("rdf:Description rdf:about=""" + Me.Variables.strFileName + """ "))
     .Write(FormatElement("Date") + "" + FormatElement("Date", True))
     .Write(FormatElement("ValidFrom") + "" + FormatElement("ValidFrom", True))
     .Write(FormatElement("ValidTo") + "" + FormatElement("ValidTo", True))
    
      ....
    
    End With
    

    【讨论】:

      猜你喜欢
      • 2013-07-28
      • 2013-08-25
      • 2020-05-15
      • 1970-01-01
      • 1970-01-01
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多