在MVC应用程序显示/编辑XML [英] Displaying / editing xml in an MVC app
问题描述
我需要保持在一个SQL数据库中的XML列
I need to maintain an xml column in a SQL database.
一)在我的详情页面 - 我只是想为漂亮的XML显示此列 - 像浏览器会。
所以不是XML的一个大的块(如<富><酒吧和GT;<数据>吲; /数据><数据>二< /数据><数据> 3< /数据>< /条><其它>别的>< /其它>< / foo的>
)我想它分裂出与新行$ b每一个新标签$ b(例如:
a) in my details page - I just want to display this column as "pretty" xml - like the browser would.
So instead of one big block of xml (e.g. <foo><bar><data>one</data><data>two</data><data>three</data></bar><other>something else></other></foo>
) I want it split out 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>
和
二)在我的编辑页面我想要一个简单的形式与标签作为标题(黑体为实例)和节点值作为可编辑的文本框 - 但我想这是动态地从XML创建本身。我不想硬编码在我的代码标记标签,但遍历XML并获取他们的飞行。
b) in my edit page I want a simple form with the tags as headings (in bold for instance) and the node values as editable text boxes - but I want this to be created dynamically from the xml itself. I don't want to hard-code the tag labels in my code, but loop through the xml and fetch them on the fly.
我使用C#.NET我与SQL Server的数据库和LINQ to SQL MVC应用程序。
I'm using c# .net for my MVC application with Sql Server as the database and LINQ to SQL.
推荐答案
有关你的第一个问题,你可以把XML字符串在的XDocument
。
For your first question you can put the XML string in a 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();
现在在你看来目前在<预><代码方式>
HTML元素
Now in your view present the value of ViewData["XmlData"] in a <pre><code>
HTML element.
这篇关于在MVC应用程序显示/编辑XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!