Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile a schema that uses a DataSet (xs:schema)?

I have created the simplest web service in c#:

public void AddData(DataSet ds)

The generated schema (Wsdl) looks like this:

<s:schema xmlns:s="http://www.w3.org/2001/XMLSchema">
...
<s:element ref="s:schema" />
...
</s:schema>

Note the schema does not contain any import/include elements.

I am trying to load this schema to a c# System.Xml.XmlSchema and add it to System.Xml.XmlSchemaSet:

var set = new XmlSchemaSet();
var fs = new FileStream(@"c:\temp\schema.xsd", FileMode.Open);
var s = XmlSchema.Read(fs, null);
set.Add(s);            
set.Compile();

The last line throws this exception:

The 'http://www.w3.org/2001/XMLSchema:schema' element is not declared.

It kind of makes sense: The schema generated by .Net uses the "s:schema" type which is declared in a schema which is not imported.

  1. Why does .Net create a non valid schema?
  2. How to compile the schema anyway? Whay I did is download the schema in http://www.w3.org/2001/XMLSchema and added it to the XmlSchemaSet also. This did not work since that online schema contains DTD definition. I had to manually remove it and now all works. Does this make sense or am I missing something?
like image 768
Yaron Naveh Avatar asked Nov 15 '22 12:11

Yaron Naveh


1 Answers

  1. I would call it a bug. It is though very unusual to see an XML Schema referencing elements from the http://www.w3.org/2001/XMLSchema namespace.
  2. What you did is the right way - almost; in general, you should be able to compile an XML Schema file that uses a DOCTYPE reference; just make sure that the DTD is available at the specified location (or available through an XML resolver) and your reader settings are configured not to prohibit DTD processing (either the obsoleted ProhibitDtd or DtdProcessing properties on XmlReaderSettings, by default those are true).
like image 156
Petru Gardea Avatar answered Jan 16 '23 04:01

Petru Gardea