recommendations needed for using xsd schema in a class library

W

wh1974

I need to move some code which at present is residing in some .aspx
codebehind files into a separate class library.

One of the functions makes use of an xml schema to create the structure
for a DataSet object which is returned to the caller. Currently the
schema is stored in an .xsd file which exists in the /schemas folder
underneath the root of the website.

If I were to move this function into a class, I'm unsure of the correct
way I should be accessing the .xsd file. The class needs to be portable
and so mustn't assume that it's running as part of a web app and thus
shouldn't look in the /schemas folder.

Am I right in thinking that the only way is to distribute the .xsd file
with the .dll used for the new class library I intend to create.

Wayne.
 
M

Matt Berther

Hello wh1974,

Can you place the schema as an embedded resource in your new dll? You could
then provide a method that returns the schema with some code like this:

[C#]
public string GetSchema()
{
using (Stream strm = Assembly.GetExecutingAssembly().GetManifestResourceStream("My.Namespace.Schema.xsd"))
{
StreamReader rdr = new StreamReader(strm);
return rdr.ReadToEnd();
}
}
 
W

wh1974

Yes, this is exactly what I'm looking for. I just wasn't sure it was
possible as I haven't much experience embedding resources in an
assembly.

I'll take a look at this,
thanks,
Wayne.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top