开发者

Generate xml from form inputs

开发者 https://www.devze.com 2023-01-12 16:25 出处:网络
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 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 even开发者_开发百科t and can generate xml. Is there any better automated way?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号