如何使用 SSIS 包将 XML 文件加载到数据库中?
我在 Visual Studio 2008 中使用 SSIS。我有许多 XML 文件需要处理并放入现有的数据库结构 (SQL Server 2005) 中。这是我第一次尝试使用 SSIS,但有点卡住了。我找到了 XML 数据流任务,为其分配了一个测试 xml 文件及其关联的 XSD,并将一个节点映射到数据库表。我的问题是,如何将多个 xsd 节点与多个表关联起来?我当然不必为每个表设置 XML 源吗?
I am using SSIS in Visual Studio 2008. I have many XML files that I need to process and place into an existing DB structure (SQL Server 2005). This is my first attempt at using SSIS and am a little stuck. I have found the XML Data Flow task, assigned it a test xml file and it's associated XSD, and mapped one node to a Database Table. My question is, how do I associate many xsd nodes with many tables? Surely I don't have to set up an XML source for each table?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
下面是一个可能的选项,演示如何将具有相同定义的多个 XML 文件加载到 SQL Server 表中。该示例使用
SQL Server 2008 R2
和SSIS 2008 R2
。此处显示的示例在XML Source
组件的帮助下,使用 SSISData Flow Task
将三个 XML 文件加载到 SQL 表中。分步过程:
dbo.Items
的表。Items.xsd
的 XSD 文件。Items_1.xml
、Items_2.xml
和Items_3.xml
使用 XML 文件 部分下提供的内容。FileExtension
、FilePath
和FolderPath
,如屏幕截图 #1 所示。SQLServer
的 OLE DB 连接以连接到 SQL Server 实例,如屏幕截图 #2 所示。Control Flow
选项卡上,在 Foreach 循环容器中放置一个Foreach 循环容器
和一个Data Flow Task
,如屏幕截图所示 # 3。Foreach 循环容器
,如屏幕截图 #4 和 #5 所示。数据流任务
以导航到数据流
选项卡。放置一个XML Source
组件和一个OLE DB Destination
,如屏幕截图 #6 所示。XML Source
,如屏幕截图 #7 和 #8 所示。 XML 文件路径将从变量 FilePath 中检索。该变量将由Foreach 循环容器
填充。OLE DB 目标
,如屏幕截图 #9 和 #10 所示。dbo.Items
中的数据现在包含三个 XML 文件中的数据。希望有帮助。
SQL 脚本:
XSD 文件
XML 文件
Items_1.xml
Items_2.xml
Items_3.xml
屏幕截图 #1:
屏幕截图 #2 :
屏幕截图#3:
屏幕截图 #4:
屏幕截图 #5:
屏幕截图 #6:
< img src="https://i.sstatic.net/cEqLB.png" alt="6">
屏幕截图 #7:
屏幕截图 #8:
屏幕截图#9:
屏幕截图 #10:
屏幕截图 #11:
屏幕截图 #12:
屏幕截图 #13: >
屏幕截图 #14:
Here is a possible option which demonstrates how to load multiple XML files having same definition into an SQL Server table. The example uses
SQL Server 2008 R2
andSSIS 2008 R2
. The example shown here loads three XML files into an SQL table using SSISData Flow Task
with the help ofXML Source
component.Step-by-step process:
dbo.Items
using the script given under SQL Scripts section.Items.xsd
in the folder path C:\temp\xsd using the content provided under XSD File section.Items_1.xml
,Items_2.xml
andItems_3.xml
in the folder path C:\temp\xml using the content provided under XML Files section.FileExtension
,FilePath
andFolderPath
as shown in screenshot #1.SQLServer
to connect to the SQL Server Instance as shown in screenshot #2.Control Flow
tab, place aForeach loop container
and aData Flow Task
within the Foreach loop container as shown in screenshot #3.Foreach Loop container
as shown in screenshots #4 and #5.Data Flow Task
to navigate to theData Flow
tab. Place anXML Source
component and anOLE DB Destination
as shown in screenshot #6.XML Source
as shown in screenshot #7 and #8. The XML file path will be retrieved from the variable FilePath. This variable will be populated by theForeach Loop container
.OLE DB Destination
as shown in screenshots #9 and #10.dbo.Items
now contains the data present in three XML files.Hope that helps.
SQL Scripts:
XSD File
XML Files
Items_1.xml
Items_2.xml
Items_3.xml
Screenshot #1:
Screenshot #2:
Screenshot #3:
Screenshot #4:
Screenshot #5:
Screenshot #6:
Screenshot #7:
Screenshot #8:
Screenshot #9:
Screenshot #10:
Screenshot #11:
Screenshot #12:
Screenshot #13:
Screenshot #14:
您还需要将
@[user::FilePath]
添加到数据流任务中的[XML Source].[XMLData]
,否则包会显示无源包执行后发现文件。You also need to add
@[user::FilePath]
to the[XML Source].[XMLData]
in the data flow task or the package says no source file found after package execution.