I am a total nube with XML and am struggling with a simple XML import into SQL 2005. Lots of boring code to follow: (In short though, my basic question is this: What in the world are my tables supposed to look like? I have a Database named "Cube", a Table named "Cube" with 2 columns, Currency and Rate, respectively)
If I can see how the table schema should be, that should be half, if not all, the battle.
The error thrown is: System.Runtime. InteropServices .COMexception: "Schema: Relationship expected n 'Cube'."
Thank you in advance
The XML File:
The Schema File:
My C# Code that is supposed to dump the XML data into my SQL Server 2005 database
If I can see how the table schema should be, that should be half, if not all, the battle.
The error thrown is: System.Runtime. InteropServices .COMexception: "Schema: Relationship expected n 'Cube'."
Thank you in advance
The XML File:
<?xml version="1.0" encoding="UTF-8" ?>
- <gesmes:Envelop e xmlns:gesmes="h ttp://www.gesmes.org/xml/2002-08-01" xmlns="http://www.ecb.int/vocabulary/2002-08-01/eurofxref">
<gesmes:subject >Reference rates</gesmes:subject>
- <gesmes:Sende r>
<gesmes:name>Eu ropean Central Bank</gesmes:name>
</gesmes:Sender>
- <Cube>
- <Cube time="2007-11-26">
<Cube currency="USD" rate="1.4845" />
<Cube currency="JPY" rate="160.96" />
<Cube currency="BGN" rate="1.9558" />
...
<Cube currency="ZAR" rate="10.1240" />
</Cube>
</Cube>
</gesmes:Envelope >
- <gesmes:Envelop e xmlns:gesmes="h ttp://www.gesmes.org/xml/2002-08-01" xmlns="http://www.ecb.int/vocabulary/2002-08-01/eurofxref">
<gesmes:subject >Reference rates</gesmes:subject>
- <gesmes:Sende r>
<gesmes:name>Eu ropean Central Bank</gesmes:name>
</gesmes:Sender>
- <Cube>
- <Cube time="2007-11-26">
<Cube currency="USD" rate="1.4845" />
<Cube currency="JPY" rate="160.96" />
<Cube currency="BGN" rate="1.9558" />
...
<Cube currency="ZAR" rate="10.1240" />
</Cube>
</Cube>
</gesmes:Envelope >
The Schema File:
<?xml version="1.0"?>
<xs:schema attributeFormDe fault="unqualif ied" elementFormDefa ult="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Cube">
<xs:complexType >
<xs:sequence>
<xs:element minOccurs="0" name="Cube">
<xs:complexType >
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbo unded" name="Cube">
<xs:complexType >
<xs:attribute name="currency" type="xs:string " use="optional" />
<xs:attribute name="rate" type="xs:decima l" use="optional" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="time" type="xs:date" use="optional" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<xs:schema attributeFormDe fault="unqualif ied" elementFormDefa ult="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Cube">
<xs:complexType >
<xs:sequence>
<xs:element minOccurs="0" name="Cube">
<xs:complexType >
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbo unded" name="Cube">
<xs:complexType >
<xs:attribute name="currency" type="xs:string " use="optional" />
<xs:attribute name="rate" type="xs:decima l" use="optional" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="time" type="xs:date" use="optional" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
My C# Code that is supposed to dump the XML data into my SQL Server 2005 database
string connStr;
connStr = "provider=SQLNC LI;Data Source=.\\SQLEX PRESS;Initial Catalog=Cube;In tegrated Security=SSPI";
SQLXMLBULKLOADL ib.SQLXMLBulkLo ad objBL = new SQLXMLBULKLOADL ib.SQLXMLBulkLo ad();
objBL.Connectio nString = connStr;
objBL.BulkLoad = true;
objBL.XMLFragme nt = true;
objBL.KeepIdent ity = false;
objBL.ErrorLogF ile = "C:\\BulkLoadEr rors.xml";
objBL.Execute(" C:\\DailyExchan geRates\\Schema .XSD", "C:\\DailyExcha ngeRates\\eurof xref-daily.xml");
connStr = "provider=SQLNC LI;Data Source=.\\SQLEX PRESS;Initial Catalog=Cube;In tegrated Security=SSPI";
SQLXMLBULKLOADL ib.SQLXMLBulkLo ad objBL = new SQLXMLBULKLOADL ib.SQLXMLBulkLo ad();
objBL.Connectio nString = connStr;
objBL.BulkLoad = true;
objBL.XMLFragme nt = true;
objBL.KeepIdent ity = false;
objBL.ErrorLogF ile = "C:\\BulkLoadEr rors.xml";
objBL.Execute(" C:\\DailyExchan geRates\\Schema .XSD", "C:\\DailyExcha ngeRates\\eurof xref-daily.xml");