Thursday, October 23, 2008

Load xsd file from assembly

First, you need to add xsd file to resource by changing build action to "Embedded Resource".
To access this file from code write something like:


XmlSchemaSet schemas = new XmlSchemaSet();
Assembly assembly = Assembly.GetExecutingAssembly();
Stream stream = assembly.GetManifestResourceStream("Namespace.ServiceDescription.xsd");
schemas.Add("", XmlReader.Create(new StreamReader(stream)));

1 comment:

The web guy said...

my requirement is I have load the xsd as embedded resource which I am able to do that . later i need to do like below
//schemaSet.Add("something", @"path");

when I try to do that passing path as xmlreader.create () it fails. but when I hardcode the path it works.