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

  • Home
  • SEARCH
  • 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 9219311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:05:13+00:00 2026-06-18T03:05:13+00:00

Given that I have a following xml: <div id=Main> <div class=quote> This is a

  • 0

Given that I have a following xml:

<div id="Main">
    <div class="quote">
        This is a quote and I don't want this text
    </div> 
    <p>
        This is content.
    </p>
    <p>  
        This is also content and I want both of them
    </p>
</div>

Is there “a XPath” to help me select inner text of div#Main as a single node, but must exclude texts of any div.quote.

I just want the text: “This is content.This is also content and I want both of them”

Thanks in advance

Here is the code to test the XPath, I’m using .NET with HtmlAgilityPack but I believe the xPath should work with any languages

[Test]
public void TestSelectNode()
{
    // Arrange 
    var html = "<div id=\"Main\"><div class=\"quote\">This is a quote and I don't want this text</div><p>This is content.</p><p>This is also content and I want both of them</p></div>";
    var xPath = "//div/*[not(self::div and @class=\"quote\")]/text()";

    var doc = new HtmlDocument();
    doc.LoadHtml(html);

    // Action
    var node = doc.DocumentNode.SelectSingleNode(xPath);

    // Assert
    Assert.AreEqual("This is content.This is also content and I want both of them", node.InnerText);
}

The test was failed obviously because the xPath is still not correct.

Test 'XPathExperiments/TestSelectNode' failed:
    Expected values to be equal.

    Expected Value : "This is content.This is also content and I want both of them"
    Actual Value   : "This is content."
  • 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-18T03:05:15+00:00Added an answer on June 18, 2026 at 3:05 am

    I don’t think there is an XPath that will give you this as a single node, because the values you’re trying to obtain aren’t a single node. Is there a reason you can’t do this?

    StringBuilder sb = new StringBuilder();
    // Action
    var nodes = doc.DocumentNode.SelectNodes(xPath);
    foreach(var node in nodes)
    {
       sb.Append(node.InnerText);
    }
    
    // Assert
    Assert.AreEqual("This is content.This is also content and I want both of them", 
                    sb.ToString());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given that I have the following WCF service: class LookUpService { public List<County> GetCounties(string
I have the following bit of code, I expect that given cstdio is included
I have the following expression that should match the entire given word in case
Given the following code below, how can I have it modified such that it
Given that I have this resultset structure (superfluous fields have been stripped) Id |
I have the following line of xml that I'm trying transform using XSLT but
I have the following example of an SVG that was given to me by
I can't seem to figure this one out. I have the following XML file:
I have an XML document that contains the following structure: Its more or less
I have the following xml. Given, a UID , Manufacturer Name and Image Layout

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.