使用 XML Bulk Load 将简单表加载到 SQL Server 的 XSD 示例

发布于 2024-10-20 04:42:30 字数 3812 浏览 10 评论 0原文

我正在尝试使用批量加载将一个相对简单的 xml 文件作为表加载到 SQL Server 2008 中。我的主要问题是制作一个适用于批量加载的 XSD。这是我当前的 XSD。我要创建的表将仅包含 nvarchar 字段和日期时间字段。

我知道我在组合 XSD 时存在错误。现在 XSD 正在工作,但批量加载未加载任何数据。

我确实在寻找可以使用批量加载成功加载到 SQL Server 中的 XSD 和 XML 文件的示例。这允许我指定最大长度和数据类型。 XML 将包含一些非标准字符,因此我已使用该数据。

下面是我的 XSD 和 XML 示例。谢谢。

<?xml version="1.0" ?>
<xsd:schema targetNamespace="urn:schemas-microsoft-com:sql:SqlRowSet1" xmlns:schema="urn:schemas-microsoft-com:sql:SqlRowSet1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sqltypes="http://schemas.microsoft.com/sqlserver/2004/sqltypes" elementFormDefault="qualified" xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
<xsd:import namespace="http://schemas.microsoft.com/sqlserver/2004/sqltypes" schemaLocation="http://schemas.microsoft.com/sqlserver/2004/sqltypes/sqltypes.xsd"/>
<xsd:element name="FWO2-2011-03-03T22-53-47" sql:relation="XMLTESTTBL2">
<xsd:complexType>
<xsd:attribute name="fIld" type="sqltypes:int" use="required"/>
<xsd:attribute name="o">
<xsd:simpleType>
<xsd:restriction base="sqltypes:nvarchar" sqltypes:localeId="1033" sqltypes:sqlCompareOptions="IgnoreCase IgnoreKanaType IgnoreWidth" sqltypes:sqlSortId="52">
<xsd:maxLength value="255"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="n">
<xsd:simpleType>
<xsd:restriction base="sqltypes:nvarchar" sqltypes:localeId="1033" sqltypes:sqlCompareOptions="IgnoreCase IgnoreKanaType IgnoreWidth" sqltypes:sqlSortId="52">
<xsd:maxLength value="255"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="f">
<xsd:simpleType>
<xsd:restriction base="sqltypes:nvarchar" sqltypes:localeId="1033" sqltypes:sqlCompareOptions="IgnoreCase IgnoreKanaType IgnoreWidth" sqltypes:sqlSortId="52">
<xsd:maxLength value="255"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="s" type="sqltypes:int"/>
<xsd:attribute name="a" type="sqltypes:int"/>
<xsd:attribute name="l" type="sqltypes:datetime"/>
<xsd:attribute name="d" type="sqltypes:datetime"/>
<xsd:attribute name="e">
<xsd:simpleType>
<xsd:restriction base="sqltypes:nvarchar" sqltypes:localeId="1033" sqltypes:sqlCompareOptions="IgnoreCase IgnoreKanaType IgnoreWidth" sqltypes:sqlSortId="52">
<xsd:maxLength value="255"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="b" type="sqltypes:datetime"/>
</xsd:complexType>
</xsd:element>
</xsd:schema>

<?xml version="1.0" ?>
<dataroot xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FWO2-2011-03-03T22-53-47.xsd" generated="2008-05-08T16:37:19">
<FWO2-2011-03-03T22-53-47>
    <n><![CDATA[2007 Protiviti Pricing Tool.zip]]></n>
    <s>3073536</s>
    <f><![CDATA[C:\Users\ethkin01\Desktop\Desktop\2011-02-06]]></f>
    <a>32</a>
    <l>1/28/2011 3:27:43 PM</l>
    <d>1/12/2011 12:09:31 PM</d>
    <e><![CDATA[.zip]]></e>
    <b>1/12/2011 12:09:31 PM</b>
</FWO2-2011-03-03T22-53-47>
<FWO2-2011-03-03T22-53-47>
    <n><![CDATA[2010 Updated 1-11-11.xlsm]]></n>
    <s>1149607</s>
    <f><![CDATA[C:\Users\ethkin01\Desktop\Desktop\2011-02-06]]></f>
    <a>32</a>
    <l>1/11/2011 4:59:46 PM</l>
    <d>1/11/2011 4:59:45 PM</d>
    <e><![CDATA[.xlsm]]></e>
    <b>1/11/2011 4:59:45 PM</b>
</FWO2-2011-03-03T22-53-47>
</dataroot>

I am trying to get a relatively simple xml file to load into SQL Server 2008 as a table using bulk load. My primary issue is crafting a XSD that works with bulk load. Here is my current XSD. The table I am looking to create will only have nvarchar fields and datetime fields.

I know I have errors in how I put together the XSD. Now the XSD is working but bulk load is not loading any data.

I am really looking for an example of a XSD and XML file that can be successfully loaded into SQL Server using Bulk Load. That allows me to specify the max length and data type. The XML will include some non standard characters so I have used for that data.

Below are a sample of my XSD and XML. Thanks.

<?xml version="1.0" ?>
<xsd:schema targetNamespace="urn:schemas-microsoft-com:sql:SqlRowSet1" xmlns:schema="urn:schemas-microsoft-com:sql:SqlRowSet1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sqltypes="http://schemas.microsoft.com/sqlserver/2004/sqltypes" elementFormDefault="qualified" xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
<xsd:import namespace="http://schemas.microsoft.com/sqlserver/2004/sqltypes" schemaLocation="http://schemas.microsoft.com/sqlserver/2004/sqltypes/sqltypes.xsd"/>
<xsd:element name="FWO2-2011-03-03T22-53-47" sql:relation="XMLTESTTBL2">
<xsd:complexType>
<xsd:attribute name="fIld" type="sqltypes:int" use="required"/>
<xsd:attribute name="o">
<xsd:simpleType>
<xsd:restriction base="sqltypes:nvarchar" sqltypes:localeId="1033" sqltypes:sqlCompareOptions="IgnoreCase IgnoreKanaType IgnoreWidth" sqltypes:sqlSortId="52">
<xsd:maxLength value="255"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="n">
<xsd:simpleType>
<xsd:restriction base="sqltypes:nvarchar" sqltypes:localeId="1033" sqltypes:sqlCompareOptions="IgnoreCase IgnoreKanaType IgnoreWidth" sqltypes:sqlSortId="52">
<xsd:maxLength value="255"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="f">
<xsd:simpleType>
<xsd:restriction base="sqltypes:nvarchar" sqltypes:localeId="1033" sqltypes:sqlCompareOptions="IgnoreCase IgnoreKanaType IgnoreWidth" sqltypes:sqlSortId="52">
<xsd:maxLength value="255"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="s" type="sqltypes:int"/>
<xsd:attribute name="a" type="sqltypes:int"/>
<xsd:attribute name="l" type="sqltypes:datetime"/>
<xsd:attribute name="d" type="sqltypes:datetime"/>
<xsd:attribute name="e">
<xsd:simpleType>
<xsd:restriction base="sqltypes:nvarchar" sqltypes:localeId="1033" sqltypes:sqlCompareOptions="IgnoreCase IgnoreKanaType IgnoreWidth" sqltypes:sqlSortId="52">
<xsd:maxLength value="255"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="b" type="sqltypes:datetime"/>
</xsd:complexType>
</xsd:element>
</xsd:schema>

<?xml version="1.0" ?>
<dataroot xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FWO2-2011-03-03T22-53-47.xsd" generated="2008-05-08T16:37:19">
<FWO2-2011-03-03T22-53-47>
    <n><![CDATA[2007 Protiviti Pricing Tool.zip]]></n>
    <s>3073536</s>
    <f><![CDATA[C:\Users\ethkin01\Desktop\Desktop\2011-02-06]]></f>
    <a>32</a>
    <l>1/28/2011 3:27:43 PM</l>
    <d>1/12/2011 12:09:31 PM</d>
    <e><![CDATA[.zip]]></e>
    <b>1/12/2011 12:09:31 PM</b>
</FWO2-2011-03-03T22-53-47>
<FWO2-2011-03-03T22-53-47>
    <n><![CDATA[2010 Updated 1-11-11.xlsm]]></n>
    <s>1149607</s>
    <f><![CDATA[C:\Users\ethkin01\Desktop\Desktop\2011-02-06]]></f>
    <a>32</a>
    <l>1/11/2011 4:59:46 PM</l>
    <d>1/11/2011 4:59:45 PM</d>
    <e><![CDATA[.xlsm]]></e>
    <b>1/11/2011 4:59:45 PM</b>
</FWO2-2011-03-03T22-53-47>
</dataroot>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑叹一世浮沉 2024-10-27 04:42:30

在 www.sourceforge.net 上尝试 xsd2db

try xsd2db at www.sourceforge.net

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文