I'm reading an RSS XML and adding each news to a tag <li>
I need every <li>
tag to be inside a <div>
tag, how can I do this through HtmlGenericControl?
This way
<div>
<li><span>Ações contra dengue prosseguem em Araruama – <a href="#">Leia mais</a></span></li>
</div>
<div>
<li><span>Laboratório em Campinas identifica 'impressão digital' do vírus da zika – <a href="#">Leia mais</a></span></li>
</div>
<div>
<li><span>Agentes arrombam casas fechadas em Recife contra o Aedes aegypti – <a href="#">Leia mais</a></span></li>
</div>
<div>
<li><span>Universidade de Sorocaba coordena três estudos sobre o Aedes aegypti – <a href="#">Leia mais</a></span></li>
</div>
The following is the code below:
private void AddMenuItem()
{
XmlDocument rssXmlDoc = new XmlDocument();
// Load the RSS file from the RSS URL
rssXmlDoc.Load("http://g1.globo.com/dynamo/luta-contra-a-dengue/rss.xml");
// Parse the Items in the RSS file
XmlNodeList rssNodes = rssXmlDoc.SelectNodes("rss/channel/item");
StringBuilder rssContent = new StringBuilder();
// Iterate through the items in the RSS file
foreach (XmlNode rssNode in rssNodes)
{
XmlNode rssSubNode = rssNode.SelectSingleNode("title");
string title = rssSubNode != null ? rssSubNode.InnerText : "";
rssSubNode = rssNode.SelectSingleNode("link");
string link = rssSubNode != null ? rssSubNode.InnerText : "";
HtmlGenericControl li = new HtmlGenericControl("li");
noticias.Controls.Add(li);
HtmlGenericControl span = new HtmlGenericControl("span");
span.InnerText = title;
HtmlGenericControl anchor = new HtmlGenericControl("a");
anchor.Attributes.Add("href", link);
anchor.InnerText = "Leia Mais";
li.Controls.Add(span);
li.Controls.Add(anchor);
}
}