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

Posted by Yaron Naveh on Stack Overflow See other posts from Stack Overflow or by Yaron Naveh
Published on 2010-03-07T15:44:18Z Indexed on 2010/03/16 22:41 UTC
Read the original article Hit count: 513

Filed under:
|
|
|
|

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?

© Stack Overflow or respective owner

Related posts about Xml

Related posts about xml-schema