Geeks With Blogs

News For all those who are interested, the .NET User Group Meetings here in Winnipeg are starting up again next Thursday, check out Winnipeg's .Net user group Home Page for details.
Evil Dev's Blog Plots, Schemes, and Plans to take over the Devleoper world.... Mu hahahaha
Today, I was assigned a task at work, which involved taking a CSV format flat file and submit it to a third-party web service. Well the webservice that the data needed to be posted to, is not a .NET based webservice, so the hook-ups needed to be done manually.

The webservice is setup to accept an ISO Standard XML format called ADF, it's an eLead based schema used within the automotive industry to exchange prospect data from system to system. I took a look around Google, but wasn't able to find a .NET library for producing the format, so I set about writing my own. I was lucky enough to get an XDR Schema definition from the third party, which defines their implementation of the standard.

Turns out, there's a neat little console utility provided by Microsoft, in the form of the xsd.exe. One feature of this little tool is to convert XDR format schema declarations, into the more modern "XSD" format that is Microsoft's current standard. Another feature, is to take an existing XSD file, and generate .NET objects that serialize into XML honoring that XSD. Sure, the generated code isn't exactly the most api friendly (using arrays instead of generic lists), and it kind of forces you to initialize everything, instead of intuitively flowing.

I would like it more if you could do something like this:
Dim prospect As New Prospect()
prospect.ContactInfo.Emails.Add(new Email(""))

Instead it's more like this:
Dim prospect As New Prospect()
Prospect.ContactInfo = new ContactInfo()
Dim emails(1) As Email
emails(0) = new Email()
emails(0).EmailAddress = ""
Prospect.ContactInfo.Emails = emails

As you can see, it's quite a bit more code and effort, but at the convience of skipping the mundane, repetitive nature of creating your model classes. Especially for a quick and dirty importer tool that's only going to exist for 60 days.

One thing I should note, I have tried using the feature in visual studio to generate an XSD off an existing XML file. It's alright, but I find that the same feature in an app called XMLPad is substantially better. It's much easier to make tweaks to it to add enumerations and tweak xs:datatypes.

Anyways, this is one of those hidden little jems that ships with .NET that I felt I should share. This tool is definately worth a looksy, and why they don't just build a feature like that inside visual studio escapes me completely. Posted on Wednesday, September 23, 2009 9:07 PM .NET Development | Back to top

Comments on this post: XSD.EXE - Little Known, Must Have

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Mitchell Lee | Powered by: