I came across a fairly unusual situation today, where a referenced
assembly contained XML schemas as embedded resources. The schemas may
(and do) contain
<xs:include> and
<xs:import>
directives, which could not be resolved when I was trying to compile
the schema: the schemas were including other schemas by relative URI
(for example, SystemConfig.xsd has an
<xs:include schemaLocation="Base.xsd" /> directive), and when the schemas are loaded from a resource there are no URIs to speak of.
After a bit of reading I settled down to write a custom implementation of XmlResolver. It's used like so:
Assembly container = typeof( anyTypeFromTheResourceAssembly ).Assembly;
XmlResourceResolver resolver = new XmlResourceResolver( container );
schema = XmlSchema.Read( stream, new ValidationEventHandler( schemaValidationEventHandler ) );
schema.Compile( new ValidationEventHandler( schemaValidationEventHandler ), resolver );
Grab it here, and do let me know if you find this useful or have any comments/questions!
Update (18:58 GMT+2): Interesting. Apparently a developer called Jay Harlow wrote a similar class
a while ago; his is VB.NET, mine is C#, but the similarity is
staggering. So if you're looking for a VB.NET version of the class,
there you are