c# - Create custom xml (ASP.NET MVC) -


i have method values database

here code

public iqueryable<timetable> gettimetables()     {         return db.timetables;     } 

here model of timetable

public partial class timetable {     public int id { get; set; }     public string company { get; set; }     public string inn { get; set; }     public string startday { get; set; }     public string startpause { get; set; }     public string endday { get; set; }     public string endpause { get; set; } } 

i need generate xml values this

<data> <worker id="000000000000">     <start>2016-08-08t08:00:00</start>     <pause>2016-08-08t13:15:49</pause>     <continue>2016-08-08t13:15:49</continue>     <end>2016-08-08t13:15:49</end> </worker> <worker id="000000000001">     <start>2016-08-08t08:00:00</start>     <pause>2016-08-08t13:15:49</pause>     <continue>2016-08-08t13:15:49</continue>     <end>2016-08-08t13:15:49</end> </worker> 

where id inn, start startday, pause startpause, continue endpause, end endday.

how can this?

this pretty straight-forward, i'm not sure you're running issues. essentially, need build xdocument like:

var xdoc = new xdocument(     new xelement("data",         timetables.select(w =>             new xelement("worker",                 new xattribute("id", w.inn),                 new xelement("start", w.startday),                 new xelement("pause", w.startpause),                 new xelement("continue", w.endpause),                 new xelement("end", w.endday)             )         )     ) ); 

then, return contentresult mime type:

return content(xdoc.tostring(), "application/xml", encoding.utf8); 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -