在使用Bulkload函数将XML文件中的数据导入到数据库时出现这个错误。映射文件Schema格式应该没什么问题,之前运行都好好的。不知道为什么会突然出现这个问题。请多多指教。用xmlspy 和 stylus studio 都校验过 a.xml 和关联的a.xsd 都是没有问题的。procedure TForm1.DataLoad;
var
    tmpIni:TINIFile;
    myObjB:OleVariant;
    XMLFileB:string;
    constrB:string;
    SchemaFileB:string;
begin
    tmpIni:=TIniFile.Create(extractfilepath(application.exename)+'A.udl');
    constrB:=tmpIni.ReadString('oledb','Provider','');
    XMLFileB:=extractfilepath(application.exename)+'xml_schema\'+Edit2.Text+'.xml';    
    SchemaFileB:=extractfilepath(application.exename)+'xml_schema\'+Edit1.Text+'schema.xsd';   
    if(FileExists(XMLFileB) AND (FileExists(SchemaFileB))) then
    begin
        myObjB:=CreateOleObject('SQLXMLBulkLoad.SQLXMLBulkload.3.0');                             //通过调用CreateOleObject函数创建Bulk Load对象
        myObjB.ConnectionString:='Provider='+constrB;                                               //通过设定Bulk Load对象的ConnectionString来连接数据库eduAdminSystem
        myObjB.ErrorLogFile:=(extractfilepath(application.exename)+'log\error.xml');               //错误信息写入error.xml文件
        myObjB.CheckConstraints:=True;
        myObjB.XMLFragment:=True;
        myObjB.SGDropTables:=False;
        myObjB.SGUseID:=False;
        myObjB.SchemaGen:=False;
        try                                                                                             //调用Bulkload的Execute方法实现批量数据导入
           myObjB.Execute(SchemaFileB,XMLFileB);
           writeLog(FormatDateTime('yyyy-mm-dd hh:mm:ss',now)+'数据导入成功');
           Label2.Caption:='结果正确'
           myObjB:=nil;
        except
          on E: Exception do
          begin
           writeLog(FormatDateTime('yyyy-mm-dd hh:mm:ss',now)+'数据导入失败'+E.Message);
           Label2.Caption:='结果错误'
           end;
        end;
     end
    else begin
       writeLog(FormatDateTime('yyyy-mm-dd hh:mm:ss',now)+'数据导入失败!文件路径错误');
    end;
end;

解决方案 »

  1.   

    'xs:schema' 字面意思这个 元素未定义。
      

  2.   

    看不出来'xs:schema' 没有定义啊
    XML文件如下<?xml version="1.0" encoding="UTF-8"?>
    <root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="testing10schema.xsd"></root>用到的Schema文件框架如下:<?xml version="1.0" encoding="UTF-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" elementFormDefault="qualified" attributeFormDefault="unqualified" xsi:schemaLocation="
    http://www.w3.org/2001/XMLSchema
    http://www.w3.org/2001/XMLSchema.xsd">
    <xs:element name="root">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="common" type="common"/>
    <xs:element name="data" type="data"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element></xs:schema>
      

  3.   

    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    这里不是定义了么?我确实不太懂。
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" elementFormDefault="qualified" attributeFormDefault="unqualified" xsi:schemaLocation="
            http://www.w3.org/2001/XMLSchema
            http://www.w3.org/2001/XMLSchema.xsd">
        <xs:element name="root">
            <xs:complexType>
                <xs:sequence>
                    <xs:element name="common" type="common"/>
                    <xs:element name="data" type="data"/>
                </xs:sequence>
            </xs:complexType>
        </xs:element></xs:schema>
      

  4.   

    xmlns:xsd  和 xmlns:sql 沒有定義,請參考範例。<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
      

  5.   

    xs:schema元素未定義(詳細定義方法可參考樓上的方法)