XML Schema och Dataset, System Error????!!!!
Hej !
Jag håller på experimentera att strukturera DataSet med XML Schema.
men jag får följande felmeddelande i rad 14 i min kod
An unhandled exception of type 'System.Xml.Schema.XmlSchemaException' occurred in system.xml.dll
Additional information: System error
här är min kod
using System; using System.Data; namespace DataSetSche...
using System;
using System.Data;
namespace DataSetSchema
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
DataSet ds = new DataSet();
ds.ReadXmlSchema(@"MoreBooks.xsd");
foreach(DataTable table in ds.Tables) //här är rad 14
{
Console.Write("Table: {0}\n-----", table.TableName);
foreach(DataColumn column in table.Columns)
{
Console.Write("{0} ({1})\t", column.ColumnName, column.DataType.ToString());
}
Console.WriteLine("\n");
}
foreach(DataRelation rel in ds.Relations)
{
Console.WriteLine("Relation: {0}, Nested: {1}", rel.RelationName, rel.Nested.ToString());
}
ds.ReadXml("Morebooks.xml");
Console.WriteLine("{0} Authors Found: ", ds.Tables["Author"].Rows.Count);
foreach(DataRow book in ds.Tables["Book"].Rows)
{
Console.WriteLine("Book {0}", book["title"]);
foreach(DataRow chapter in book.GetChildRows("BookChapters"))
{
Console.WriteLine("\tChapter: {0}", chapter["Title"]);
}
}
Console.ReadLine();
}
}
}
och här är min xsl fil. OBS den hittar xml filen och på VS i schema läget på filen får jag inga fel jag ser mina tabeller.
<?xml version="1.0" standalone="yes" ?> <xs:sche...
<?xml version="1.0" standalone="yes" ?>
<xs:schema id="Library" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schema-microsost-com:xml-msdata">
<xs:element name="Library" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unhounded">
<xs:element name="Book">
<xs:complexType>
<xs:attribute name="author" type="xs:string" />
<xs:attribute name="isbn" type="xs:string" use="required" />
<xs:attribute name="title" type="xs:string" />
<xs:attribute name="publishdate" type="xs:string" />
<xs:attribute name="publisher" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:element name="Author">
<xs:complexType>
<xs:sequence>
<xs:element name="ID" type="xs:string" minOccurs="0" />
<xs:element name="Name" type="xs:string" minOccurs="0" />
<xs:element name="Age" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Chapter">
<xs:complexType>
<xs:sequence>
<xs:element name="ISBN" type="xs:string" minOccurs="0" />
<xs:element name="Title" type="xs:string" minOccurs="0" />
<xs:element name="Page" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:unique name="PK_BookISBN" msdata:PrimaryKey="true">
<xs:selector xpath=".//Book" />
<xs:selector xpath="@isbn" />
</xs:unique>
<xs:keyref name="BookChpaters" refer="PK_BookISBN">
<xs:selector xpath=".//Chapter" />
<xs:selector xpath="ISBN" />
</xs:keyref>
</xs:element>
</xs:schema>