views:

84

answers:

2

I am working on a Windows Desktop application that will store a number of documents, there will initially be 4 different types of documents, each as a windows form, each with some common details (document ID, client ID etc), and then different fields based on the document type.

I plan on using XML to specify the fields for each form. So my question is, what is the easiest way to take an XML document and render form fields based on its content? Should I just be parsing the XML and creating form fields, or is there a quicker and easier way?

A: 

A Dynamically Generated XML Data Editor may help you.

Richard Hein
+1  A: 

If you're using XML as meta-data, and you're meta-data is relatively static (e.g. FieldName=X, DataType=Y, etc.) and doesn't have to be extended at run-time, you may consider XmlSerialization and deal with the resulting objects in code.

Having done both approaches, I can honestly say that dealing with type-safe objects is a lot cleaner than having business logic and parsing logic intertwined. That being said, it won't work (or you'll have to jump through some hoops) if you need run-time extensibility.

If your meta-data changes rarely, you may even want to consider some form of code-gen instead of dynamic form building.

Regarding Auxon's answer, YMMV with 3rd party options. I've had some which work great OOTB, saving me lots of time, and others where I've spent as much time configuring and tweaking to get results that are not quite what I would want as I would have building it myself. Depending on how critical this feature is to your application, you may want to consider rolling your own if start to see 3rd party-framework adaptation becoming a large development task.

micahtan