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 8657317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:29:34+00:00 2026-06-12T15:29:34+00:00

I have some test html page <!DOCTYPE html> <html lang=en xmlns=http://www.w3.org/1999/xhtml> <head> <meta charset=utf-8

  • 0

I have some test html page

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title>Page for test</title>
</head>
<body>
    <div class="r_tr">
        <span class="r_rs">Inner text<span class="otherSpan" style="display: none">text</span></span>
    </div>
</body>
</html>

I want to get “Inner text”.
I am using HtmlAgilityPack.
I write this method

public string GetInnerTextFromSpan(HtmlDocument doc)
{
    const string rowXPath = "//*[@class=\"r_tr\"]";
    const string spanXPath = "//*[@class=\"r_rs\"]";
    string text = null;
    HtmlNodeCollection rows = doc.DocumentNode.SelectNodes(rowXPath);
    foreach(HtmlNode row in rows)
    {
        text = row.SelectSingleNode(spanXPath).InnerText;
        Console.WriteLine("textL {0}", text);
    }
    return text;

}

but this method return “Inner texttext”.
I write some unit test for explain my problem

[Test]
public void TestGetInnerTextFromSpan()
{
    var client = new PromtTranslatorClient();
    var doc = new HtmlDocument();
    doc.Load(@"testPage.html");
    var text = client.GetInnerTextFromSpan(doc);
    StringAssert.AreEqualIgnoringCase("Inner text", text);
}

and result

Expected string length 10 but was 14. Strings differ at index 10.
  Expected: "Inner text", ignoring case
  But was:  "Inner texttext"
  ---------------------^
  • 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-06-12T15:29:35+00:00Added an answer on June 12, 2026 at 3:29 pm

    I do not know XPath but here is solution using LINQ:

    String inner = (from x in doc.DocumentNode.Descendants()
                    where x.Name == "span"
                    && x.Attributes["class"].Value == "r_rs"
                    select 
                          (from y in x.ChildNodes
                           where y.Name == "#text"
                           select y.InnerText).FirstOrDefault()
                    ).FirstOrDefault();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following html code <!DOCTYPE html> <html lang=en> <head> <meta name=viewport content=width=device-width;
I have something similar to this: <!doctype html> <html> <head> <meta charset=UTF-8> <title>JQuery Test</title>
I have some HTML Code: <html> <head> <title>css test</title> <style type=text/css> .box{width:100%;float:left;background:red} </style> </head>
I have an HTML test page for this issue here . For some reason
My entire default page is listed below. <!DOCTYPE html> <html> <head> <meta charset=utf-8 />
Suppose I have the following html: This a test of <code>some code</code>. <div class='highlight'>
<p title=The test paragraph>This is a sample of some <b>HTML you might<br>have</b> in your
I'm have some that uses jQuery.clone() to get the html of a page and
I have an aspx site: <%@ Page Language=C# AutoEventWireup=true CodeBehind=Download.aspx.cs Inherits=ATP.Management.Web.Download %> <!DOCTYPE html
I have a html page with some links. When you click on a link,

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.