xsd.exe revisited

by Jesse 12. August 2008 09:04

This morning I was having a battle royale with a small xml file and fighting with the idea of "what's the best way".  As usual, there are approx. 2 billion ways to do it, about 3 of them are the "right" way and, of course, there's 1 that's the best way.  Mildly annoyed (xml files and I have a history, mutual love/hate relationship) I tossed the question out and Lori says to use xsd.exe to create the things I need.  Ahhh yes, xsd.exe, how I remember thee.

the ole xsd has come along since last I used it with 2.0 and I was very happy to see this ...

Option Description

/enableDataBinding

Implements the INotifyPropertyChanged interface on all generated types to enable data binding. The short form is '/edb'.

enable databinding with INotify!  Sweeeeeeet.  They also include a linq aspect of it as well.  Nice.  I don't need the linq part, but that INofity will be perfect.  To create the xsd, I ran ...

xsd C:\xmldata\myXmlFile.xml /out:C:\xmldata\

and get my nice xsd file. From there, I want the classes with that awesome INotify (/edb) and I want to start on a particular element makes a cleaner class (/e:myXmlElement) and I want it in c# (/l:cs) ...

xsd C:\xmldata\myXmlFile.xsd /classes /e:myXmlElement /l:CS /edb /out:C:\xmldata

It's too bad the output class STILL comes with Arrays.  I like lists myself, but can't complain, easy fix.  Now lets make this do something useful...like this. 

StreamReader reader = new StreamReader(Server.MapPath("MyXmlFile.xml"));
XmlSerializer serial = new XmlSerializer(typeof(MyXmlFile));
MyXmlFile xmlData = new MyXmlFile();
xmlData = serial.Deserialize(reader)
as MyXmlFile;
this.RadGrid1.DataSource = xmlData;
this.RadGrid1.DataBind();

Solid.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Comments

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen

About the author

Like the description says, at my core, I'm a scientist and engineer.  I came from humble beginnings on a 486DX2 Packard Hell playing doom2 on IPX to in a small time retail shop and got into hardware (ISO layers FTW!) and it was all downhill from there.  I'm infinitely curious about almost everything and always wanting to know.

According to personality tests (real ones) I classify under "Rational" more specifically, a Fieldmarshal.  I think there's something to that.

Some of the stuff I'm currently into/researching...

Sitefinity

Ninject

Subsonic 

Currently working on ...
i did the hundred


and some extra stuff

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's, their brother, their dog, cat, ferret nor gold fish's view in anyway.  At all.  Ever.

© Copyright 2007-2009

Month List