1

I need to show any xml in table in my mvc app like in photo

https://drive.google.com/file/d/0B9JoyO0mTmhnNWplMlR6ME5PeW8/edit?usp=sharing

this is my code but it work only for one parent element in xml

enter code here String f1 = Session["doc2"].ToString();
        Value model2 = new Value();


        HttpPostedFileBase file2 = TempData["doc3"] as HttpPostedFileBase;
        var fileex = Path.GetExtension(file2.FileName);
        string xmlstr = ".xml"; 
        string strall = "";

        XDocument xml = XDocument.Parse(f1);
             var abc = xml.Root.DescendantNodes().OfType<XElement>()
                                               .Select(x => x.Name).Distinct();
            ViewBag.MyListabc = abc;
            var abcd = xml.Root.DescendantNodes().OfType<XElement>()
                                                   .Select(x => x.Value).Distinct();
            ViewBag.MyListabcd = abcd;


        model2 = new Value()
        {

            file1 = abc

        };


        //ViewBag.MyList = listelem;
        return View(model2);


    }

And this is my view

enter code here<table style="font-family: verdana,arial,sans-serif;
font-size:11px;
color:#333333;
border-width: 1px;
border-color: #666666;
border-collapse: collapse;">

@foreach (var item in ViewBag.MyListabc) {

                   <th style="border: 1px solid; width:80px">   @Html.DisplayTextFor(x => item) </th>

}</tr>

@foreach (var item in ViewBag.MyListabcd) { <td style="border: 1px solid; width:80px"> @Html.DisplayTextFor(x => item) </td>

}</tr>
</table>
Dinah
  • 52,922
  • 30
  • 133
  • 149

1 Answers1

0

You could parse your xml table to a DataTable object and then render your DataTable in your view. Some links for inspiration.

Community
  • 1
  • 1
Kunukn
  • 2,136
  • 16
  • 16