C# Creating dataset from xsd containing digital signature

1.5k Views Asked by At

Visual Studios 2005, .NET 2.0

I'm working on a messaging service that sends and receives xml messages based on a 3rd party schema file I can't modify. (I've verified the schema as valid and generated a sample xml message using Altova's XMLSpy.) The best solution I've found to handle this requirement is to create a dataset based on the schema and then populate the dataset using DataSet.ReadXml(). DataSet.WriteXml() should then be able to be used when creating messages.

When I've built DataSets off .xsd files in the past I've used the MSDataSetGenerator Custom Tool. However the schema file I have errors out when running it through the MSDataSetGenerator with the error:

Custom tool error: Failed to generate code. Unable to convert input xml file content to a DataSet. The 'http://www.w3.org/2000/09/xmldsig#:KeyInfo' element is not declared.

Below are the lines relevant to the digital signatures/KeyInfo/Signature from the schema file.

<xs:import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd"/>

Further on in the file it references 2 objects defined in that schema:

<xs:element ref="ds:Signature" minOccurs="0"/>
<xs:element ref="ds:KeyInfo" minOccurs="0"/>

I've also tried loading the schema in by doing:

DataSet ds = new DataSet();
ds.ReadXmlSchema("schema.xsd");

But that also throws the same error regarding KeyInfo not being declared.

Is there another way to create the Dataset I'm missing or an option I need to set to be able to use the MSDataSetGenerator? Or does anyone know a better way to set this up overall instead of using a dataset based on the provided schema?

1

There are 1 best solutions below

2
On

The original XML Signature schema file from W3C contains a DTD header at the top, I guess to make compatible with older XML parsers. Apparently the .Net schema reader doesn't like that. The easiest solution is to comment out the eight lines from

<!DOCTYPE ...

to ]>.