views:

1114

answers:

3

Is there a standard way to convert an XSD to an input form (ASP.NET C#) so that later on whenever a new field is added / removed from the XSD the field on the page automatically shows up or goes away respectively, is this something which needs to be developed in-house I assume there must be a way to serializes / deserializes and generates a form? Any hel would be appreciated..

A: 

Assumption: You're using XML because it is simpler for you at the moment.

Idea: Since you want to create a form to manipulate the data, I'm guessing you might be open to SQL instead of XML. This may not be the case, but you will probably find more tools to help you if you have a database backend instead of an XML/XSD backend. (Plus there are ways you can convert your data from one to another).

There are tools that create forms from databases in ASP.NET. SubSonic, for example, has a auto-scaffolding module that lets you create a database manager knowing only its schema. If the schema changes, just have SubSonic regenerate its files and your forms will have been modified. It isn't perfect, but it may go a long way, depending on your needs.

Option 1) You can create the database schema from the XSD (http://stackoverflow.com/questions/138575/how-can-i-create-database-tables-from-xsd-files) and use SubSonic from that point on. This may be even more of a pain than you original question... only you know.

Option 2) Hack the SubSonic scaffolding so that it supports your underlying XSD/XML instead of a database. You can probably re-use lots of their infrastructure (SubSonic is open source) to generate the form from an XSD.

Good luck!

Jason Kealey
+2  A: 

I don't think there's anything built in to make this fully automatic. However, you can get pretty close. Visual Studio includes a command line program called xsd.exe that you can use to automatically create a class definition from an xsd document. Once you have that class definition you can connect it to a form via an ObjectDataSource component and a DetailsView control.

Joel Coehoorn
A: 

Well, I have to say that the ObjectDataSource is not a bad idea, but this does not work if you have nested elements. On top of this, for nested elements you will have all the "..FieldSpecified" boolean fields in the DetailsView as well.

I'm still trying to figure out how to generate a ASP.NET form using an XSD file, without having to type in everything, which is monkey work.

Anyone already ran into that issue?

PS: An other approach would be to use InfoPath, but this requires licensed software to run as webforms...

Philippe