SSIS:使用变量数据从 XML 源创建 CSV 文件
在 SSIS 中,我尝试使用来自 Web 服务的数据来创建 csv 文件。
在我的控制流中,我创建了一个 Web 服务任务,它将其输出保存到用户变量中。
当 Web 服务任务完成时,它会启动数据流任务。
数据流任务有一个 XML 源,数据访问模式设置为“来自变量的 XML 数据”,指向(假定)具有来自 Web 服务的 XML 数据的变量。
在 DFT 之前和之后设置断点证明该变量已设置为我期望的 XML 文本。
例如,XML 看起来像这样(名称已更改以保护专有信息):
<?xml version="1.0" encoding="utf-16"?>
<ArrayOfMyItemObject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<MyItemObject>
<OrderID xmlns="http://webservices.mycompany.com/MyPath/">111111</OrderID>
<ItemID xmlns="http://webservices.mycompany.com/MyPath/">123456</ItemID>
</MyItemObject>
<MyItemObject>
<OrderID xmlns="http://webservices.mycompany.com/MyPath/">222222</OrderID>
<ItemID xmlns="http://webservices.mycompany.com/MyPath/">678901</ItemID>
</MyItemObject>
<MyItemObject>
<OrderID xmlns="http://webservices.mycompany.com/MyPath/">333333</OrderID>
<ItemID xmlns="http://webservices.mycompany.com/MyPath/">234567</ItemID>
</MyItemObject>
<MyItemObject>
<OrderID xmlns="http://webservices.mycompany.com/MyPath/">444444</OrderID>
<ItemID xmlns="http://webservices.mycompany.com/MyPath/">890123</ItemID>
</MyItemObject>
</ArrayOfMyItemObject>
该数据流任务只是处理为平面文件目标(csv 文件)。平面文件中的列映射到 XML 中的值。
但是,当我运行它时,我只获得列名,而没有数据。
我已经通过使用相同的 Web 服务运行另一个 Web 服务任务,但将该输出直接放入文件中,验证了该 Web 服务任务返回了我所期望的结果。
In SSIS, am attempting to use data from a web service to create a csv file.
In my Control Flow, I have created a Web Service Task that saves its output to a User Variable.
When the Web Service Task finishes, it starts a Data Flow Task.
The Data Flow Task has a single XML Source, with the Data access mode set to "XML data from variable" pointing to the variable that (supposedly) has the XML data from the web service.
Setting a breakpoint both before and after the DFT prove that that variable is being set to the XML text that I am expecting.
For example, the XML looks something like this (names changed to protect proprietary info):
<?xml version="1.0" encoding="utf-16"?>
<ArrayOfMyItemObject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<MyItemObject>
<OrderID xmlns="http://webservices.mycompany.com/MyPath/">111111</OrderID>
<ItemID xmlns="http://webservices.mycompany.com/MyPath/">123456</ItemID>
</MyItemObject>
<MyItemObject>
<OrderID xmlns="http://webservices.mycompany.com/MyPath/">222222</OrderID>
<ItemID xmlns="http://webservices.mycompany.com/MyPath/">678901</ItemID>
</MyItemObject>
<MyItemObject>
<OrderID xmlns="http://webservices.mycompany.com/MyPath/">333333</OrderID>
<ItemID xmlns="http://webservices.mycompany.com/MyPath/">234567</ItemID>
</MyItemObject>
<MyItemObject>
<OrderID xmlns="http://webservices.mycompany.com/MyPath/">444444</OrderID>
<ItemID xmlns="http://webservices.mycompany.com/MyPath/">890123</ItemID>
</MyItemObject>
</ArrayOfMyItemObject>
That data flow task simply processes into a Flat File Destination (the csv file). The columns in the flat file are mapped to the values in the XML.
However, when I run this, I only get the column names, and no data.
I have verified that the Web Service task returns what I am expecting by running another Web Service task using the same web service, but putting that output directly into a file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个答案,说明我为解决此问题所做的工作。如果有人可以更好地回答“为什么”,我会将其标记为答案。
问题在于将命名空间包含在来自 Web 服务的 XML 中,并结合在 xsd 中使用“targetNamespace”。
最初,xsd 看起来像这样:
我需要删除 targetNamespace 属性。
然后,我需要删除从 Web 服务返回的 XML 中对该命名空间的引用。为此,我在 Web 服务任务之后创建了一个脚本任务。该任务为保存 XML 文本的变量定义了一个 ReadWriteVariable,该变量将在数据流任务中传递 XML 源。
脚本的代码只是从 XML 中删除命名空间并将其返回:(
我意识到我的代码是在一行中完成的,但这更干净,并且允许我进一步修改 XML(如果我愿意)未来)。
通过这样做,XML Source 可以正确处理变量中传递的 XML。
Here is an answer that says what I've done to work around this issue. If somebody can answer better with a "why" I will mark that as the answer.
The problem was with including the namespace with the XML from the web service, combined with using "targetNamespace" in the xsd.
Originally, the xsd looked something like this:
I needed to remove the targetNamespace attribute.
Then, I needed to remove references to that namespace in the XML returned from the web service. To do that, I created a Script task right after the Web Service Task. This task has a ReadWriteVariable defined for the variable that holds the XML text, which will get passed the XML Source in the Data Flow Task.
The code of the script simply removes the namespace from the XML and returns it back:
(I realize that I code do it in one line, but this is cleaner, and allows me to further modify the XML if I'd like to in the future).
By doing this, the XML Source correctly processes the XML passed in the variable.