Generate HTML/XML Markup in C# Console Application? -


i working console application generates xml/html output. have code below includes hard-coded spaghetti markup.

is possible use razor or tool improve , make cleaner?

foreach (var file in _files) {     taglib.file f = taglib.file.create(file.fullname);     string title = f.tag.title;      string url = _urlprefix + file.name;      stringbuilder sb = new stringbuilder();      sb.append("<item>\n");     sb.appendformat("\t<title>{0}</title>\n", httputility.htmlencode(title));     sb.appendformat("\t<pubdate>{0}</pubdate>\n", file.creationtimeutc.tostring("r"));     sb.appendformat("\t<guid ispermalink=\"false\">{0}</guid>\n", url);     sb.appendformat("\t<enclosure url=\"{0}\" length=\"{1}\" type=\"audio/mpeg\" />\n", url, file.length);     sb.append("\t<itunes:subtitle></itunes:subtitle>\n");     sb.append("\t<itunes:summary></itunes:summary>\n");     sb.append("</item>\n");      items.appendline(sb.tostring()); } 

just use system.xml classes you.

https://msdn.microsoft.com/pt-br/library/system.xml(v=vs.110).aspx

sample code:

xmldocument doc = new xmldocument(); xmlelement el = (xmlelement)doc.appendchild(doc.createelement("foo")); el.setattribute("bar", "some & value"); el.appendchild(doc.createelement("nested")).innertext = "data"; console.writeline(doc.outerxml); 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -