4

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

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>

and

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.

I'm using c# .net for my MVC application with Sql Server as the database and LINQ to SQL.

2
  • so what's your question? Commented Sep 15, 2009 at 9:22
  • Sorry - I missed off the question! It's simply "how can you do this?" Thanks. Commented Sep 15, 2009 at 11:00

1 Answer 1

3

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();

Now in your view present the value of ViewData["XmlData"] in a <pre><code> HTML element.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.