如何从 XSD 模式构建数据库并导入 XML 数据 [英] How to build a database from an XSD schema and import XML data

查看:51
本文介绍了如何从 XSD 模式构建数据库并导入 XML 数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个复杂的 XSD 架构和数百个符合该架构的 XML 文件.

I have a complex XSD schema and hundreds of XML files conforming to the schema.

如何自动创建相关的 SQL Server 表来存储 XML 数据?

How do I automate the creation of related SQL Server tables to store the XML data?

我考虑过使用 xsd.exe 工具从 XSD 架构创建 C# 类,并让 Subsonic 之类的东西弄清楚如何从中制作一个闪亮的数据库,但不确定它是否是最好的方法.

I've considered creating C# classes from the XSD schema using the xsd.exe tool and letting something like Subsonic figure out how to make a shiny database out of it, but not sure if it's the best way to approach it.

有没有人设法优雅地将 XSD 文件导入 SQL Server?

Has anyone managed to elegantly import XSD files into SQL Server?

一个类似的问题有很好的答案:如何创建XSD 文件中的数据库表?

A similar question with good answers: How can I create database tables from XSD files?

推荐答案

我建议您使用 SQL Server 2008 或 2005 附带的 SQL Server Integration Services(如果您坚持使用 2000,则使用 Data Transformation Services).

I suggest you use SQL Server Integration Services, which comes with SQL Server 2008 or 2005 (Or Data Transformation Services if your stuck with 2000).

不幸的是,它没有附带 SQL Server 的免费Express"版本,但是 SQL Server Developer 版本可以用于 <100 美元,具有完整的 SQL Server Standard 功能,可以满足您的需求.

Unfortunately it doesn't come with the free "Express" version of SQL Server, however SQL Server Developer edition can be had for < $100 which has the full SQL Server Standard functionality and would suit your needs.

SSIS 是一个很大的话题,我不会在这里讨论所有的花里胡哨,但基本上是你:

SSIS is a big topic and I'm not going to go over all of the bells and whistles here but basically you:

  • 使用 BIDS(商业智能开发工作室,SSIS 附带的修改后的 Visual Studio)创建一个新的 SSIS 项目
  • 将新的数据流任务拖到控制流图面上,然后单击数据流选项卡.
  • 将XML 源"从工具箱拖到数据流面板中,然后配置 XSD 和 XML 文件位置.
  • 将 ADO.NET 数据目标从工具箱拖到数据流上,并将 XML 源的输出之一连接到 ADO.NET 目标的输入.如果您想基于 xml 模式的数据输出创建一个新表,而不是使用现有的在 ADO.NET 目标中指定连接管理器设置时单击新建",它会生成并执行适当的创建表陈述.对来自 XML 源的任何其他输出重复此操作(对于从架构生成的每个逻辑平面表都会有一个).

在将数据加载到 SQL Server 之前,您很可能需要先使用其他数据转换对象来转换数据,但这是它的一般要点.如果您需要为大量 XML 文件运行该过程,您可以将任务置于控制循环中并使用变量来设置 XML 文件位置.

You will most probably need to use other data transformation objects first to transform the data before it loaded into SQL server, but that is the general gist of it. If you need to run the process for a large amount of XML files you could put the task in a control loop and use a variable to set the XML file location.

关于在 SSIS 中使用 XML 源的 MS 文档在这里:http://msdn.microsoft.com/en-us/library/ms140277(v=SQL.100).aspx

The MS Documentation on using an XML source in SSIS is here: http://msdn.microsoft.com/en-us/library/ms140277(v=SQL.100).aspx

这篇关于如何从 XSD 模式构建数据库并导入 XML 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆