@ the office over the past few days, I’ve been embedding myself into the wonderful world of XML. In this happy land, things are …well, usually happy, until you get a crappy XSD file. Technically, the xsd is valid so you can use it and generate a class and what not by using XSD.exe /stuff. It was irritating, because this did not allow nulls, at all, anywhere and after we discovered that hey, guess what, we have no idea if any of the data will ever show up …soooo knowing that we have no choice, we neeeeeeed those nullables (I think in xsd land they’re called nillables or something or other)
Anyway, here’s a quick dirty snippet of code you can use to generate a cleaner xsd. And yes, its THAT easy.
System.Data.DataSet dataSet = new System.Data.DataSet();
dataSet.ReadXmlSchema(”C:\\mycrapXSD.xsd”);
dataSet.WriteXmlSchema(”C:\\myprettyXSD.xsd”);
Use your XSD.exe to generate your class, and as another “gotcha!” — you’ll probably see an array of an array, something like Item[][]; Rid yourself of one of the [] and all will be good in the world.