Blogger :
Michael Freidgeims Blog
All posts :
All posts by Michael Freidgeims Blog
Category :
XML
Blogged date : 2008 Jul 22
I have an existing C# file, generated a long time ago from XSD definition.
The XSD files were changed, and proxy class should be regenerated.
I've tried to use
XML Schema Definition Tool (Xsd.exe) to generate C# class, but it returned the error:
"The datatype is missing".
I've actually have two XSD files -outer and imported
Note that name of generated file is combined from the files listed
I've created the batch file to be able to rerun it
CallXSD.BAT
@call "C:\Program Files\Microsoft Visual Studio 8\VC\vcvarsall.bat" x86
xsd.exe outer.xsd imported.xsd /classes /l:cs /n:MyNamespace
rem rename outer_imported.cs as outer.cs
pause
By some reason the generated file created in some non-default encoding, which inserts 3 characters
 in the beginning.It is a minor annoyance, but when I delete them, VS shows me a warning, that wrong encoding could prevent keeping history.
The next issue was that the new XSD(.Net Framework 2.0 and 3.5) generates C# classes differently with what 1.0/1.1 XSD.exe did.
In a few places 1.1 version generated custom collection of objects, but new XSD.EXE generates array of objects, so I have to change the calls to generated classes.
I should try An XSD to .NET language code class generator that adds real punch to Microsoft's XSD Tool.
Another issue was that authors of XSD file added xsd:choice elements and it creates extra ItemsChoiceType array and enum.
Example from MSDN XmlChoiceIdentifierAttribute Class article shows how to fill pairs of arrays:
// Populate an object array with three items, one
// of each enumeration type. Set the array to the
// ManyChoices field.
object[] strChoices = new object[]{"Food", 5, 98.6};
myChoices.ManyChoices=strChoices;
// For each item in the ManyChoices array, add an
// enumeration value.
MoreChoices[] itmChoices = new MoreChoices[]
{MoreChoices.Item,
MoreChoices.Amount,
MoreChoices.Temp};
myChoices.ChoiceArray=itmChoices;
That's pity, that minor changes in XSD file causes different class properties to be generated and essential code changes to access the new properties.
