Display / edit xml in MVC application

I need to maintain an xml column in an SQL database.

a) on my details page - I just want to display this column as "pretty" xml - like in a browser. So instead of one big xml block (e.g. <foo><bar><data>one</data><data>two</data><data>three</data></bar><other>something else></other></foo>), I want it to split with each new tag on a new line (e.g.

<foo>
  <bar>
    <data>one</data>
    <data>two</data>
    <data>three</data>
  </bar>
  <other>something else></other>
</foo>

and

b) on my edit page. I need a simple form with tags in the form of headings (for example, in bold) and node values ​​as editable text fields, but I want this to be dynamically created from the xml itself. I do not want to hardcode the tag labels in my code, but iterate over the xml and display them on the fly.

I am using C # .net for my MVC application with Sql Server as a database and LINQ to SQL.

+3
1

XML XDocument.

XDocument doc = XDocument.Parse("<foo><bar><data>one</data><data>two</data><data>three</data></bar><other>something else></other></foo>");

ViewData["XmlData"] = doc.ToString();

ViewData [ "XmlData" ] <pre><code> HTML.

+3

Source: https://habr.com/ru/post/1717715/


All Articles