Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3680574
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:35:32+00:00 2026-05-19T03:35:32+00:00

How can this be done? The .InnerText Property (when used on the containing div

  • 0

How can this be done? The .InnerText Property (when used on the containing div element) is giving me the html only. Is it possible to iterate through all the li elements contained and extract their values?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T03:35:33+00:00Added an answer on May 19, 2026 at 3:35 am

    Is it possible to iterate through all
    the li elements contained and extract
    their values?

    From comment of the OP:

    Doctype is HTML 5 and it is valid
    code. – Radu

    In this case one can just use the following XPath expression:

    div//li//text()
    

    This selects all text nodes that are descendents of all li elements that are descendents of any div element that is a child of the current node.

    Using an XPath expression to select nodes in an XML (and HTML5 is well-formed XML) is the recommended, most straightforward and more reliable way than doing this with difficult to construct, difficult to test and difficult to understand and maintain regular expressions.

    Here is a complete code example:

    using System;
    using System.Xml;
    
    class TestXPath
    {
        static void Main(string[] args)
        {
            string html5Text =
    @"<html>
     <head>
     </head>
     <body>
      <div>
       <ul>
        <li>Line 1</li>
        <li>Line 2</li>
        <li>Line 3</li>
       </ul>
      </div>
     </body>
    </html>";
    
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(html5Text);
    
            string xpathExpr = @"/*/*/div//li//text()";
    
            XmlNodeList selection = doc.SelectNodes(xpathExpr);
    
            foreach (XmlNode node in selection)
            {
                Console.WriteLine(node.OuterXml);
            }
    
        }
    }
    

    when the above application is executed, the wanted, correct result is produced:

    Line 1
    Line 2
    Line 3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can this be done by setting a property? I'd prefer that approach then to
can ASP.NET controls be used with generics? Never seen this done and want a
Can this be done w/ linqtosql? SELECT City, SUM(DATEDIFF(minute,StartDate,Completed)) AS Downtime FROM Incidents GROUP
This isn't working. Can this be done in find? Or do I need to
Maybe this cannot be done, but please help or suggest how this can be
I don't think this can be done cleanly, but I'll ask anyway. I have
I'm sure I've done this before, but can't find any example of it! Grrr...
I've done numerous searches and I realize that I can just download this file
Has anyone seen this before - and can anything be done about it? This
The default [1..5] gives this [1,2,3,4,5] and can also be done with the range

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.