SSIS - 将输入转换为 XML 的 VB 脚本组件
我对 (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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SQL 代码:
我得到了这个输出
SQL code:
I got this OutPut