views:

15

answers:

2

i have a form in Asp.net MVC. On submitting i want to generate the xml of the input. Whats the best way of doing it?

I can do it by capturing the names/id of form in Post event and can generate xml. Is there any better automated way?

A: 

A form could be submitted using either application/x-www-form-urlencoded or multipart/form-data. In both cases you get name=value pairs which cannot automatically be mapped to an hierarchical structure such as XML without any manual indication. As far as XML creation is concerned you may take a look at the XDocument class or XmlWriter. Another alternative is to rely on the default model binder which will instantiate a view model passed as an action parameter that you could serialize to XML.

Darin Dimitrov
A: 

Are you trying to submit XML over HTTP from the form? If so, you'll need javascript. Jquery can be very helpful here too.

If you are trying to generate XML on the server-side, check out XmlSerialization, its the only way to fly.

Wyatt Barnett