开发者

SSIS - VB Script Component to Convert Input to XML

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   A开发者_Go百科AA     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


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜