开发者

How do I send an XML document to an ASP.NET MVC page for manipuation

I have some hierarchical data stored as an multiple XML files on the server according to a vendor's schema. In my ASP.NET MVC (2!) application, I'd like the user to choose one of these hierarchies (i.e. file -- I provide a list in my controller's Index action). When the user selects one to "edit" my edit action shoul开发者_C百科d return a page that presents the XML hierarchy (it's a representation of a folder tree). So my thoughts are that the view would return HTML that contained a JQuery on load ajax call back to the server for the XML data -- at which point I would present the tree using one of the many JQuery tree controls. On the client side I'd like the user to manipulate the tree and when done, I'd like to post back the new hierarchy where I would replace the original XML file that represents that hierarchy.

So my questions are:

  • What form should I use to send the data down? XML or JSON?. If I send down XML then I would have to not only read the XML -- which JQuery can do -- but I would also have to be able to modify that XML and then send it back. Can I use JQuery to modify this XML DOM? And will all the namespace declarations be preserved?

  • What form should I send the data back? If I originally sent the client the hierarchy as JSON (using JsonResult), then presumably I would have a hierarchy of javascript objects. What options would I have to post that back? Would I have to recreate the XML reprentation on the client and post that back? Or should I serialize back to JSON, post that to the server, and then have the server do the work of recreating the XML according to the schema.

Thanks for any advice.


Hmmm, good question, assuming I understood you correctly.

This question really depends on the jQuery hierarchal tree plugin you end up using and what input type it requires to present the tree. Could you list (with links) the potential candidates?

However, this is my take:

  1. Drop down list on the "ChooseXMLToEditPage", with each drop down pointing to a specific XML file name.

  2. The submit button on this page will post to an action that will grab the XML file from the server, then parse it to meet the input requirements of the jQuery plugin and return the view with the parsed data in it. You can use AJAX to get this information if you don't want to insert the data in the HTML source, but the important part is parsing it to the jQuery plugin's specification.

  3. When the user is done editing the tree, see what information is available to use by your jQuery plugin. Maybe it returns XML, maybe JSON. If it returns either, it shouldn't be too hard to parse those to the proper schema, do this on server side, as C#/VB.NET are much more powerful.

  4. If the jQuery plugin doesn't return XML or JSON, then, using jQuery, take the raw HTML of the tree, post it to some action and parse it to XML using some type of HTML library (check out Html Agility Pack, or if you prefer use Regular Expression to Parse HTML).

Again, this is all really dependent on the jQuery plugin. But at the end of the day, the jQuery plugin will give you some type of output that can be parsed to match your schema.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜