Howard Pinsley
Howard Pinsley

Reputation: 11478

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 should 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:

Thanks for any advice.

Upvotes: 0

Views: 994

Answers (1)

Omar
Omar

Reputation: 40202

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.

Upvotes: 1

Related Questions