Embedded XSD files with includes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

(.NET 2.0)

I want to embed the XML schema files into my DLL. However, this schema is
"split" in several files, i.e., they use xs:include. Note that the include is
relative and contains only the name of the file, i.e., the fragments are
supposed to be in the same directory.

For simplicity, suppose we have a main schema "a.xsd", which includes
"b.xsd" and "c.xsd".

In my code, I add the main schema (that includes all others) using:

xmlSettings.Schemas.Add(SCL2006_NAMESPACE, new
XmlTextReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("a.xsd"));

Now, when I open (validating) an instance file, using:
XmlReader.Create(new XmlTextReader(file, _nt), settings)

there is an exception saying that there is an undefined complex type. This
is because it did not read the included XSDs (b.xsd and c.xsd). How can I
ensure that it would do it?

I tried to solve the problem this way: I added to the xmlSettings.Schemas
all parts of the full schema, i.e, beside "a.xsd", "b.xsd" and "c.xsd".

Then, it works fine - up to a point. If the directory containing the
instance file contains as well one or all files constituting the schema, then
I get an exception that a simple type (from XSD "b.xsd") has already been
declared.

So it looks like it does process the schema files only when loading the
instance file, and looks for includes in the directory where the instance
file is. How can I avoid this behavior?

I've tried to add XmlSchema to the xmlSettings.Schemas, however this does
not solve the problem either...

Thanks for any help!
 
Melbrouff said:
Hi,

(.NET 2.0)

I want to embed the XML schema files into my DLL. However, this schema is
"split" in several files, i.e., they use xs:include. Note that the include is
relative and contains only the name of the file, i.e., the fragments are
supposed to be in the same directory.

For simplicity, suppose we have a main schema "a.xsd", which includes
"b.xsd" and "c.xsd".

In my code, I add the main schema (that includes all others) using:

xmlSettings.Schemas.Add(SCL2006_NAMESPACE, new
XmlTextReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("a.xsd"));

Now, when I open (validating) an instance file, using:
XmlReader.Create(new XmlTextReader(file, _nt), settings)

there is an exception saying that there is an undefined complex type. This
is because it did not read the included XSDs (b.xsd and c.xsd). How can I
ensure that it would do it?

I tried to solve the problem this way: I added to the xmlSettings.Schemas
all parts of the full schema, i.e, beside "a.xsd", "b.xsd" and "c.xsd".

Then, it works fine - up to a point. If the directory containing the
instance file contains as well one or all files constituting the schema, then
I get an exception that a simple type (from XSD "b.xsd") has already been
declared.

So it looks like it does process the schema files only when loading the
instance file, and looks for includes in the directory where the instance
file is. How can I avoid this behavior?

I've tried to add XmlSchema to the xmlSettings.Schemas, however this does
not solve the problem either...

Thanks for any help!

AFAIK, you can't do this. The files are embedded resources, how should
the XmlReader know where to look? A solution would be to extract the
resources and put them on the hard disk, process them and delete the
files afterwards.

HTH,
Andy
 

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

Back
Top