Using XSD schema for field validation when databinding to XML

I'd like to create an application, part of which involves the customer creating XML documents compliant with a government standard schema.
Much of the data will be filled in automatically, but parts will be manually entered by the customer.

For the customer data, I want to create a few simple forms for data input. I thought I could use data binding for this.
I would like each input field on the form to be validated against the schema definition of that element in the xml file, rather than just validating the finished file all in one go.

I know that InfoPath can do this sort of thing, but there does not appear to be a framework in Windows forms for attaching schema validation rules to specific input fields.

I'm considering creating a custom datasource or extender provider to hook up an input field with some logic to fetch the corresponding schema definition from the schema object model, discover the validation rules for that element and validate the input against them.

If anyone has any design tips or suggestions I would be very interested.

It seems to me like something a lot of people would like to do, so if anyone knows of any existing code, or third party controls that already have this functionality please let me know.

[1269 byte] By [eddwo] at [2008-2-13]
# 1
Wow - not an easy thing to do (although it sounds easy). If you create your own data source, I'd suggest you use ICustomTypeDescriptor - and I'd be interested to see what you come up with...

Joe

JoeStegman at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 2
I don't really understand. How do you suggest I use ICustomTypeDescriptor?
Do you mean I need to create a class that represents each XML element that I bind to, then implement ICustomTypeDescriptor on those classes to add properties that represent the schema rules for that element?


eddwo at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 3

No - this really depends on how your types are setup and how users will consume them. My thought was you'd have your types implement ICustomTypeDescriptor. Your types would implement ICustomTypeDescriptor and return PropertyDescriptors that map to the real properties but take your schema rules into account. You'd also need a mechanism to handle validation errors (or you could throw - but again, this depends on your consumption model).

Joe

JoeStegman at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...