Geeks With Blogs

News My Blog has been moved to https://mfreidge.wordpress.com

Michael Freidgeim's Blog My Blog has been moved to https://mfreidge.wordpress.com
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
Thanks to the post: XSD.exe is kicking my butt, man...redux , it pointed me to specify all necessary files on the commandline.
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.

Another problem with XSD generated classes is that it disables  step into debugging even on methods that you  extended in partial classes by specifying DebuggerStepThroughAttribute for classes. Workarounds are described in XSD.exe and DebuggerStepThrough post.  Issue reported to MS Feedback.

I should try An XSD to .NET language code class generator that adds real punch to Microsoft's XSD Tool.
or Sample Code Generator 1.4.2.1

Another issue was that authors of XSD file added   xsd:choice  elements and it creates extra ItemsChoiceType array and enum.I described how I addressed it in my post XmlChoiceCollection class to access XSD generated properties for choice XML elements

 

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. Posted on Tuesday, July 22, 2008 12:28 AM Web Services/WCF | Back to top


Comments on this post: Generate C# class from XSD file.

# re: Generate C# class from XSD file.
Requesting Gravatar...
Here's a good tutorial about how to create that classes, hope i can help :

http://www.stjhimy.com/2009/10/17/playing-around-with-xmls-and-xsds-net-smiles-for-you/

enjoy it.
Left by Jhimy on Oct 18, 2009 4:56 PM

# re: Generate C# class from XSD file.
Requesting Gravatar...
i know this is an old post, but i just came across it.

" in the beginning"..

those are unicode byte order marks (BOM).. that's why visual studio complains about it when you delete them..
Left by Scott on Jul 21, 2010 4:11 PM

# re: Generate C# class from XSD file.
Requesting Gravatar...
Why not try oxmlibrary? http://oxmlibrary.codeplex.com
It's better in my experience...
Left by Moshon on Dec 22, 2010 3:37 PM

# re: Generate C# class from XSD file.
Requesting Gravatar...
the refered link @jhimy has moved to

http://www.affordablewebdeveloper.com/2009/10/17/playing-around-with-xmls-and-xsds-net-smiles-for-you/
Left by Raj on Feb 24, 2012 8:08 PM

Your comment:
 (will show your gravatar)


Copyright © Michael Freidgeim | Powered by: GeeksWithBlogs.net