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:
<?xml version="1.0" encoding="UTF-8" ?>
- <gesmes:Envelope xmlns:gesmes="http://www.gesmes.org/xml/2002-08-01" xmlns="http://www.ecb.int/vocabulary/2002-08-01/eurofxref">
<gesmes:subject>Reference rates</gesmes:subject>
- <gesmes:Sender>
<gesmes:name>European 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 attributeFormDefault="unqualified" elementFormDefault="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="unbounded" name="Cube">
<xs:complexType>
<xs:attribute name="currency" type="xs:string" use="optional" />
<xs:attribute name="rate" type="xs:decimal" 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=SQLNCLI;Data Source=.\\SQLEXPRESS;Initial Catalog=Cube;Integrated Security=SSPI";
SQLXMLBULKLOADLib.SQLXMLBulkLoad objBL = new SQLXMLBULKLOADLib.SQLXMLBulkLoad();
objBL.ConnectionString = connStr;
objBL.BulkLoad = true;
objBL.XMLFragment = true;
objBL.KeepIdentity = false;
objBL.ErrorLogFile = "C:\\BulkLoadErrors.xml";
objBL.Execute("C:\\DailyExchangeRates\\Schema.XSD" , "C:\\DailyExchangeRates\\eurofxref-daily.xml");