SSIS - 将输入转换为 XML 的 VB 脚本组件

发布于 2024-12-07 05:40:49 字数 1434 浏览 1 评论 0原文

我对 (VB) 脚本完全陌生,并且正在尝试在 SSIS 脚本组件中找到一种方法,将 3 个输入列转换为一个 XML 结构化输出列。

Input:

ID  NAME    DATE
1   AAA     2011-01-01
2   BBB     2011-02-01
3   CCC     2011-03-01


Expected Output:

<output>
<row>
    <id>1</id>
    <name>AAA</name>
    <date>2011-01-01</date>
</row>
<row>
<id>2</id>
    <name>BBB</name>
    <date>2011-02-01</date>
</row>
<row>
    <id>3</id>
    <name>CCC</name>
    <date>2011-03-01</date>
</row>
</output>

我正在寻找的解决方案需要可扩展,因为可以有 x 列,并且脚本只需要迭代每一列并生成名称标签和值。

我通过将每个值输出到通用“param”节点中来实现这一目标,但不确定如何获取列名称。

    Public Overrides Sub ProcessInput(ByVal InputID As Integer, ByVal Buffer As Microsoft.SqlServer.Dts.Pipeline.PipelineBuffer)

        inputBuffer = Buffer

        MyBase.ProcessInput(InputID, Buffer)
    End Sub

    Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)

        Dim xml_string As String = ""
        Dim counter As Integer

        xml_string = "<output>"

        For counter = 0 To inputBuffer.ColumnCount - 1

            xml_string = xml_string + "<param>" + inputBuffer.Item(counter).ToString() + "</param>"

        Next

        xml_string = xml_string + "<output>"

        Row.xmloutput = xml_string

    End Sub

Im completely new to (VB) scripting, and am trying to find a way in an SSIS script component to convert 3 input columns into one XML structured output column.

Input:

ID  NAME    DATE
1   AAA     2011-01-01
2   BBB     2011-02-01
3   CCC     2011-03-01


Expected Output:

<output>
<row>
    <id>1</id>
    <name>AAA</name>
    <date>2011-01-01</date>
</row>
<row>
<id>2</id>
    <name>BBB</name>
    <date>2011-02-01</date>
</row>
<row>
    <id>3</id>
    <name>CCC</name>
    <date>2011-03-01</date>
</row>
</output>

The solution im looking for needs to be scalable, in that there can be x number of columns and the script just needs to iterate through each column and generate the name tag and value.

I have kind of got there by outputting each value into a generic "param" node, but am unsure how to get the column names.

    Public Overrides Sub ProcessInput(ByVal InputID As Integer, ByVal Buffer As Microsoft.SqlServer.Dts.Pipeline.PipelineBuffer)

        inputBuffer = Buffer

        MyBase.ProcessInput(InputID, Buffer)
    End Sub

    Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)

        Dim xml_string As String = ""
        Dim counter As Integer

        xml_string = "<output>"

        For counter = 0 To inputBuffer.ColumnCount - 1

            xml_string = xml_string + "<param>" + inputBuffer.Item(counter).ToString() + "</param>"

        Next

        xml_string = xml_string + "<output>"

        Row.xmloutput = xml_string

    End Sub

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌吟 2024-12-14 05:40:49

SQL 代码:

  SELECT [ID]
  ,rtrim([Name]) [Name]
  ,[Date]
  FROM [tempdb].[dbo].[Table1]
  FOR XML PATH('row'), ROOT ('output')

我得到了这个输出

  <output>
    <row>
      <ID>1</ID>
      <Name>AAA</Name>
      <Date>2011-01-01</Date>
    </row>
    <row>
      <ID>2</ID>
      <Name>BBB</Name>
      <Date>2011-02-01</Date>
    </row>
    <row>
      <ID>3</ID>
      <Name>CCC</Name>
      <Date>2011-03-01</Date>
    </row>
  </output>

SQL code:

  SELECT [ID]
  ,rtrim([Name]) [Name]
  ,[Date]
  FROM [tempdb].[dbo].[Table1]
  FOR XML PATH('row'), ROOT ('output')

I got this OutPut

  <output>
    <row>
      <ID>1</ID>
      <Name>AAA</Name>
      <Date>2011-01-01</Date>
    </row>
    <row>
      <ID>2</ID>
      <Name>BBB</Name>
      <Date>2011-02-01</Date>
    </row>
    <row>
      <ID>3</ID>
      <Name>CCC</Name>
      <Date>2011-03-01</Date>
    </row>
  </output>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文