Hello,
I am writing a program that generates automatically XSD schema's, based on
the definitions in our database. Everything works fine, except for one
thing.
The files contain a header, a body and a footer. As the header and footer
is the same for every document, I want to include them in my document
schema. When executing the included code, I get this exception:
System.InvalidCastException: Specified cast is not valid.
at System.Xml.Schema.XmlSchema.LoadExternals(XmlSchem aCollection
schemaCollection, XmlNameTable nameTable, SchemaNames schemaNames,
ValidationEventHandler validationEventHandler, XmlSchema schema, Hashtable
loadedSchemas)
at System.Xml.Schema.XmlSchema.Compile(XmlSchemaColle ction collection,
XmlNameTable nameTable, SchemaNames schemaNames, ValidationEventHandler
validationEventHandler, String targetNamespace, SchemaInfo schemaInfo,
Boolean compileContentModel, XmlResolver resolver)
at System.Xml.Schema.XmlSchema.Compile(ValidationEven tHandler
validationEventHandler)
This is my code.
Dim schema As New XmlSchema
schema.Version = "1.0"
schema.TargetNamespace = UMSNAMESPACE
schema.Namespaces = XsdHelper.GetSchemaNamespaces()
schema.Includes.Add(XmlSchema.Read(New IO.FileStream(headerFileName,
IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.ReadWrite), AddressOf
validation))
schema.Includes.Add(XmlSchema.Read(New IO.FileStream(bodyFileName,
IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.ReadWrite), AddressOf
validation))
schema.Includes.Add(XmlSchema.Read(New IO.FileStream(footerFileName,
IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.ReadWrite), AddressOf
validation))
schema.Items.Add(XsdHelper.getSchemaAppInfo("env_" + title.Text))
schema.Items.Add(XsdHelper.getSchemaDocumentation( "env_" + title.Text))
schema.Compile(AddressOf validation)
kind regards,
Sam Vanhoutte