批量加载时xml架构出错

时间:2014-08-20 15:35:26

标签: xml xsd

我有一个简单的xsd,我用于xmlBulkUpload。当我尝试它时,我得到错误"架构:关于' FileSchm'的关系的父/子表。不匹配。" 任何人都可以找出原因?

XSD文件:

    <?xml version="1.0" encoding="utf-8"?>
    <xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified"
                xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                xmlns:sql="urn:schemas-microsoft-com:mapping-schema">


      <xsd:annotation>
        <xsd:appinfo>
          <sql:relationship name="xmlFile_xmlSchema"
          parent="xmlFile"
          parent-key="FileID"
          child="xmlSchema"
          child-key="File_ID" />
        </xsd:appinfo>
      </xsd:annotation>

      <xsd:element name="File">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element name="FileName" minOccurs="1" maxOccurs="1" type="xsd:string" />
            <xsd:element name="FileSchm" sql:relationship="xmlFile_xmlSchema">
              <xsd:complexType>
                <xsd:sequence>
                  <xsd:element name="SchemaName" minOccurs="1" maxOccurs="1" type="xsd:string" />
                </xsd:sequence>
              </xsd:complexType>
            </xsd:element>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>

</xsd:schema>

数据库表:

CREATE TABLE [dbo].[xmlFile](
    [FileID] [bigint] IDENTITY(1,1) PRIMARY KEY,
    [FileName] [nvarchar](256) NOT NULL
    )

CREATE TABLE dbo.xmlSchema (
    [SchemaID] [int] IDENTITY (1,1) PRIMARY KEY,
    [File_ID] [bigint]  REFERENCES dbo.xmlFile ( FileID ),
    [SchemaName] [nvarchar](50) NOT NULL
)

示例XML:

<?xml version="1.0" encoding="UTF-8"?>
<File>
  <FileName>TestFileName</FileName>
    <FileSchm>
      <SchemaName>Finance</SchemaName>
    </FileSchm>

    <FileSchm>
      <SchemaName>Marketing</SchemaName>
    </FileSchm>
</File>

批量加载的c#代码:

public string BulkLoadXML(string xmlFilePath, string xsdFilePath)
{
try
{
Stopwatch sw = new Stopwatch();
sw.Start();
objBL.KeepIdentity = false;
objBL.ErrorLogFile = @"D:\_Maryam\XML Data\error.xml";
objBL.Execute(xsdFilePath, xmlFilePath);
sw.Stop();
TimeSpan ts = sw.Elapsed;
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10);

return "Completed Bulk upload in " + elapsedTime + " ms!";
}
catch (Exception e)
{
return e.ToString();
}
}

非常感谢!

0 个答案:

没有答案