XML, XSD, and C#

January 21st, 2008 by jason Leave a reply »

I have really started diving into some of the new XML features of SQL Server.  I know I am a  little late to the game, but I was spending my time learning WPF, WCF, WF, Silverlight, and C# 3.0 (sheesh, Microsoft)!

SQL Server 2005 comes with some cool client-side libraries for using XML in .Net.  One of the things I like is that you can pull and push XML in and out of a command object, and enforce the data schema of the XML with an XSD schema.  Still, working with XML in .Net is a chore and is not strongly typed.  But I just ran across this command:

xsd.exe -c -l:c# -n:namespace schema.xsd

You can find documentation here for the arguments of xsd.exe.

This creates a class or classes for all of the defined elements of the XSD.  To generate classes object instances at runtime, simply use the XmlSerializer!  What I really like about all of this is that xsd.exe generates *partial* classes.  You can then write additional business logic, if needed, for the classes.

Nice.

Advertisement

Leave a Reply

You must be logged in to post a comment.