Groups | Blog | Home
all groups > dotnet xml > july 2006 >

dotnet xml : XmlSchemaImport and XmlSchema.Write


doughboy
7/18/2006 10:28:25 AM
I create a schema in memory and then I can write to a file fine. But
as soon as I add an import element I get an error when it goes to write
to the file.
The error message is:

The type System.Xml.Schema.XmlSchemaImport was not expected. Use the
XmlInclude or SoapInclude attribute to specify types that are not known
statically.

What does this mean? Is there a limitation to when I can use
<xs:import> vs <xs:include>?
And why does it occur when I go to write it out? Is the schema
compiled at the time and is it looking to resolve the external schema?
If so, that description doesn't seem very accurate.

The following is the code that generates the schema (content gets
filled in later):

private XmlSchema GenerateBlankSchema()
{
XmlSchema schema = new XmlSchema();
schema.ElementFormDefault = XmlSchemaForm.Qualified;
schema.AttributeFormDefault = XmlSchemaForm.Unqualified;
schema.TargetNamespace =
"http://schemas.infinityinfo.com/coretypes";
schema.Namespaces.Add("ii",
"http://schemas.infinityinfo.com/datatypes");
XmlSchemaImport import = new XmlSchemaImport();
import.Namespace =
"http://schemas.infinityinfo.com/datatypes";
schema.Items.Add(import);
return schema;
}

I've tried the overload that takes XmlNamespaceManager as the second
parameter but same thing.

Jiho
Zafar Abbas
7/19/2006 9:18:35 AM
You should not add the XmlSchemaImport object to schema.items, rather to
schema.Includes collection.

[quoted text, click to view]

doughboy
7/26/2006 6:00:55 AM
Thanks! That was it.

[quoted text, click to view]
AddThis Social Bookmark Button