赞
踩
ssis导入xml
We can use an SSIS package to perform various tasks such as data import, transform, and get output in various formats. Once we launch Visual Studio 2019 and create an integration services project, it shows you various tasks in the SSIS toolbox. In this article, we will explore the XML Task in the SSIS.
我们可以使用SSIS包执行各种任务,例如数据导入,转换和获取各种格式的输出。 启动Visual Studio 2019并创建集成服务项目后,它将在SSIS工具箱中向您显示各种任务。 在本文中,我们将探讨SSIS中的XML任务 。
We use XML Task to validate, compare the XML documents, apply various transformations. It uses Extensible Stylesheet Language Transformations (XSLT) for applying the transformation on the XML data. We can also merge XML documents from various sources and create a comprehensive XML document.
我们使用XML Task来验证,比较XML文档,应用各种转换。 它使用可扩展样式表语言转换(XSLT)将转换应用于XML数据。 我们还可以合并来自各种来源的XML文档,并创建一个全面的XML文档。
Let’s drag this XML task in the Control flow and explore its various configurations.
让我们将此XML任务拖到Control流中,并探索其各种配置。
Now, double-click on the XML editor to open the XML task editor.
现在,双击XML编辑器以打开XML任务编辑器。
Let’s have a look at the options available in the task editor:
让我们看一下任务编辑器中可用的选项:
By default, it shows the XML editor in the Diff operation mode. For the Diff operation type, we have further options in the Diff Option group.
默认情况下,它以Diff操作模式显示XML编辑器。 对于“差异”操作类型,“ 差异选项”组中还有其他选项。
Expand the DiffOptions to check various options for Diff.
展开DiffOptions以检查Diff的各种选项。
Let’s create two XML documents and compare them using this XML task in the SSIS package. For the demonstration purpose, I use the XML specified in the Microsoft docs.
让我们创建两个XML文档,并使用SSIS包中的XML任务比较它们。 出于演示目的,我使用Microsoft文档中指定的XML 。
Base file:
基本文件:
Second XML File:
第二个XML文件:
In the source type, create a new file connection and specify the location of the XML document we want to use as a base file.
在源类型中,创建一个新的文件连接,并指定我们要用作基本文件的XML文档的位置。
Similarly, we need to provide the path of the second XML file in the Second Operand group. Select the SecondOperandTYpe as a File Connection. We can use the option DirectInput or variable as well from the drop-down menu.
同样,我们需要在Second Operand组中提供第二个XML文件的路径。 选择SecondOperandTYpe作为文件连接。 我们也可以从下拉菜单中使用选项DirectInput或变量。
Additionally, we need to configure the path for the DiffGram file that captures the difference in both XML documents. First, set the property SaveDiffGram to True. In the new file connection manager, select the option to create the file and specify the file name and directory.
另外,我们需要为DiffGram文件配置路径,以捕获两个XML文档中的差异。 首先,将属性SaveDiffGram设置为True。 在新的文件连接管理器中,选择选项以创建文件并指定文件名和目录。
We do not want our SSIS package to fill in case it finds any difference in both XML’s file. I would go with the default setting FailOnDifference as False. You can change it to True in case you want the package to fail in case of differences.
我们不希望我们的SSIS包填充以防万一它发现两个XML文件中的任何差异。 我将默认设置FailOnDifference设置为False。 如果希望软件包因差异而失败,可以将其更改为True。
In the connection managers, we can see the base XML, second XML file along with the DiffGram file to capture the differences.
在连接管理器中,我们可以看到基本XML,第二个XML文件以及DiffGram文件,以捕获差异。
Click on Start to execute the SSIS Package. We can see the package is successful because we have selected the property FailOnDifference as False.
单击开始以执行SSIS包。 我们可以看到包成功了,因为我们选择了FailOnDifference属性为False。
Let’s open the DiffGram file from the directory we specified during configuration. In the base and source file, we have additional data for the book id 102. It does not exist in the base file, so you got the difference in the output.
让我们从配置过程中指定的目录中打开DiffGram文件。 在基础文件和源文件中,我们还有书ID 102的其他数据。该文件在基础文件中不存在,因此您得到了输出上的差异。
We have book id 101 in both the XML documents. Let’s change the content for book id 101 in the base XML.
在两个XML文档中,我们都有书ID 101。 让我们在基本XML中更改书籍ID 101的内容。
Save this XML file and rerun the package. This time we get a failure for the SSIS package. Click on the Execution results, and we see that it failed because the DiffGram file already exists.
保存此XML文件并重新运行程序包。 这次我们的SSIS包失败了。 单击执行结果,我们看到它失败,因为DiffGram文件已经存在。
Go back to the control flow and open the XML task editor. In the output, we have the option to overwrite the output file if it already exists. Switch the value for OverWriteDestination as True.
返回控制流并打开XML任务编辑器。 在输出中,我们可以选择覆盖输出文件(如果已经存在)。 将OverWriteDestination的值切换为True。
Click Ok and execute the package. The package runs fine this time. Open the DiffGram file and note the difference in both XML’s. You can see here that it highlights the difference if it exists in an element value as well.
单击确定,然后执行该程序包。 这次包运行良好。 打开DiffGram文件,并注意两种XML的区别。 您可以在此处看到,如果元素值中也存在差异,则会突出显示差异。
In the previous section, we compared the XML document using the diff operation of the XML task. Let’s use the merge operation. As highlighted earlier, merge operations add the content of the second document into the base document.
在上一节中,我们使用XML任务的diff操作比较了XML文档。 让我们使用合并操作。 如前所述,合并操作将第二个文档的内容添加到基本文档中。
Let’s open the XML task editor and change the operation type to Merge. It changes the configuration options corresponding to the merge operation.
让我们打开XML任务编辑器,并将操作类型更改为Merge。 它更改与合并操作相对应的配置选项。
Before we go further, let’s view the XML documents we want to merge into a new file. Here, the left file is the base XML(1), and Right-side XML is the XML we wish to merge with the base file.
在继续之前,让我们查看要合并到新文件中的XML文档。 在这里,左侧文件是基础XML(1),右侧XML是我们希望与基础文件合并的XML。
Let’s make the following changes in the merge file editor.
让我们在合并文件编辑器中进行以下更改。
Once we have done the configuration for merge operation, click Ok and execute the SSIS package.
完成合并操作的配置后,单击“确定”并执行SSIS包。
Package execution is successful. Let’s open the merge XML file and see if it merged the following XML into the base XML. In the following screenshot, we view the XML content into the base XML document.
包执行成功。 让我们打开合并XML文件,看看它是否将以下XML合并为基本XML。 在下面的屏幕快照中,我们将XML内容查看到基本XML文档中。
In this article, we learned about the XML task in the SSIS package. We explored the XML files comparison and merge operations using the Diff and Merge operations. You can also explore other XML operations such as Patch, validate, XPath and XSLT.
在本文中,我们了解了SSIS包中的XML任务。 我们探讨了使用Diff和Merge操作进行XML文件比较和合并操作。 您还可以探索其他XML操作,例如Patch,validate,XPath和XSLT。
翻译自: https://www.sqlshack.com/an-overview-of-the-xml-task-in-ssis-packages/
ssis导入xml
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。