Include .xsd in class

Include .xsd in class

Post by Dave » Tue, 05 Mar 2002 23:23:45



Is there a way to include a XML schema document in an assembly (.dll)? We
want to have the XML validation done in machine code as opposed to
constantly opening/closing the schema document. How can this be done?
 
 
 

Include .xsd in class

Post by Yussef Alkhamrich » Wed, 06 Mar 2002 08:02:00


I don't know if you're using VS.NET, but if you do it's pretty easy to embed
the .xsd into you're assembly.
View the properties of your .xsd file in VS.NET, in the dropdown box for
'Build Action' select 'Embedded Resource'.
Now you can get a stream to the .xsd by the following code (my default
namespace is NS and the .xsd file has the name schema.xsd):

System.Reflection.Assembly assembly;
System.IO.Stream stream;

assembly = typeof(SomeClassInAssembly).Assembly;
stream = assembly.GetManifestResourceStream("NS.schema.xsd");

You now get a stream of the schema from the resource that's embedded in the
assembly.


Quote:> Is there a way to include a XML schema document in an assembly (.dll)? We
> want to have the XML validation done in machine code as opposed to
> constantly opening/closing the schema document. How can this be done?


 
 
 

Include .xsd in class

Post by Peter Wu [Microsoft » Thu, 07 Mar 2002 11:58:26


Dave,

Yussef suggests a good way to set the XSD as an Embedded Resource.

Also, as I just replied to you in another NG, you may take a look at the System.Xml.Schema
namespace. Good luck!

Thanks,
Peter Wu
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure?  For information about the Strategic Technology Protection Program and to
order your FREE Security Tool Kit, please visit http://www.microsoft.com/security.

 
 
 

Include .xsd in class

Post by Dave » Fri, 08 Mar 2002 00:50:31


This worked. Thanks.


> I don't know if you're using VS.NET, but if you do it's pretty easy to
embed
> the .xsd into you're assembly.
> View the properties of your .xsd file in VS.NET, in the dropdown box for
> 'Build Action' select 'Embedded Resource'.
> Now you can get a stream to the .xsd by the following code (my default
> namespace is NS and the .xsd file has the name schema.xsd):

> System.Reflection.Assembly assembly;
> System.IO.Stream stream;

> assembly = typeof(SomeClassInAssembly).Assembly;
> stream = assembly.GetManifestResourceStream("NS.schema.xsd");

> You now get a stream of the schema from the resource that's embedded in
the
> assembly.



> > Is there a way to include a XML schema document in an assembly (.dll)?
We
> > want to have the XML validation done in machine code as opposed to
> > constantly opening/closing the schema document. How can this be done?