Add a div for each li tag - HtmlGenericControl

1

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 &ndash; <a href="#">Leia mais</a></span></li>
            </div>
            <div>
                <li><span>Laboratório em Campinas identifica 'impressão digital' do vírus da zika &ndash; <a href="#">Leia mais</a></span></li>
            </div>
            <div>
                <li><span>Agentes arrombam casas fechadas em Recife contra o Aedes aegypti &ndash; <a href="#">Leia mais</a></span></li>
            </div>
            <div>
                <li><span>Universidade de Sorocaba coordena três estudos sobre o Aedes aegypti &ndash; <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);

    }


}
    
asked by anonymous 09.04.2016 / 07:23

1 answer

-1

The solution is easier than I thought .. I added

HtmlGenericControl div = new HtmlGenericControl("div");
noticias.Controls.Add(div);

Then at the end

div.Controls.Add(li);
    
10.04.2016 / 18:02