Thanks for your quick response. I took your second suggestion and, using
Reflector.exe to peek inside xsd.exe, figured out how the schema generation
was being done there. I thought others might be interested in the final
result, so I'm going to post it here. I'd also love any feedback if somebody
can see a better way to do it. For some reason this code feels a little
hacked together for me.
Anyway, here is the code:
<code>
public static XmlSchema GetSchemaForType ( Type type ) {
XmlReflectionImporter importer = new XmlReflectionImporter ( );
XmlSchemas schemas = new XmlSchemas ( );
XmlSchemaExporter exporter = new XmlSchemaExporter ( schemas );
XmlTypeMapping mapping = importer.ImportTypeMapping ( type );
exporter.ExportTypeMapping ( mapping );
// NOTE: If you want to receive validation events, you must pass
in an
// appropriate ValidationEventHandler delegate for the first
parameter
schemas.Compile ( null, false );
return schemas[mapping.Namespace];
}
</code>
Thanks,
John Glover
[quoted text, click to view] "Kevin Yu [MSFT]" wrote:
> Hi John,
>
> This is what xsd.exe do to get the schema from a class. I think you have
> two options here:
>
> 1. Write your class to a file and invoke xsd.exe to get the output schema.
> This will require additional files to be generated.
> 2. Implement your own schema generator. You can use the reflector to check
> what xsd.exe is doing. It's not that complex.
>
> Hope that helps.
>
> Kevin Yu
> =======
> "This posting is provided "AS IS" with no warranties, and confers no
> rights."
>