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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:54:00+00:00 2026-06-04T01:54:00+00:00

Follow-up to: HTML XPath: Extracting text mixed in with multiple tags? I’ve made my

  • 0

Follow-up to: HTML XPath: Extracting text mixed in with multiple tags?

I’ve made my test case more difficult:

<div id="mw-content-text"><h2><span class="mw-headline" >CIA</span></h2>
<ol>
<li><small>Military</small> Central <a href="/Intelligence_Agency.html">Intelligence Agency</a>.</li>
<li>Culinary <a href="/Institute.html">Institute</a> of <a href="/America.html">America</a>.<br/>Renowned cooking school.</li>
</ol>

</div>  

I have the same goal, namely, extracting:

  • Central Intelligence Agency
  • Culinary Institute of America

Can I selectively choose which tags are excluded?

I’ve tried things like (for removing ‘Military’):

id('mw-content-text')/ol/li[not(self::small)]

but that condition is applied to the ‘li’ node as a whole, so it’s not affected.

And if I do something similar

id('mw-content-text')/ol/li/*[not(self::small)]

then I’m only filtering on the children, and even though I successfully throw away ‘Military’, I’ve also thrown away ‘Central’, ‘Culinary’, i.e. text from the parent.

I had understood the tree to be something like:

div -- li  
          -- small -- Military  
          -- Central  
          -- a     -- Intelligence Agency  
    -- li  
          -- Culinary  
          -- a     -- Institute  
          -- of  
          -- a    -- America  
          -- br  
          -- Renowned cooking school.  

Is that correct? Is there a way to say ‘text elements of li and li’s descendents EXCEPT descendents of small?’ How about ‘… EXCEPT a br element and all following text elements’?

Again, use of (partial) Pythonic solutions are also acceptable, though XPath is preferred.


After sitting down to read Chapter 6 ‘XPath and XPointer’ of ‘Learning XML, Second Edition’ by Erik Ray, I think I’ve got a grasp on it. I came up with the following formulation:

id('mw-content-text')/ol/li//text()[not(parent::small) and not(preceding-sibling::br)]

In this case, it doesn’t seem possible to concatenate the resulting node set of text nodes. When we simply feed the ‘li’ element to the string function, then the resulting string-value is simply a concatenation of element node li’s descendants. But in this case, we need to do further filtering, such that we result in a node set (of qualifying text nodes) instead of a single element node. Regarding concatenating node sets, a helpful SO question can be found here: XPath to return string concatenation of qualifying child node values

Any advice how to improve this solution?

  • 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-04T01:54:01+00:00Added an answer on June 4, 2026 at 1:54 am

    Use:

     /*/ol/li/descendant-or-self::*
              [text() and not(self::small)]
                  /text()[not(preceding-sibling::br)]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the follow HTML <div>This is some <span>special <a href=#>text</a></span> and it's super</div>
I have the follow HTML <div id=outerID> <input id=inner1 type=text value=button1/> <input id=inner2 type=text
My HTML is as follow. <div class=box w-25 h-25> <p>test</p> </div> <div class=box w-30
Ie., follow this link: http://googleblog.blogspot.com/2012/04/toward-simpler-more-beautiful-google.html Notice, you'll see some spinning gears, and then the
I have 3 html box as follow: <div class=tabs> <ul class=tabNav> <li><a href=#video>Video Gallery</a></li>
I've created an xpath expression as follows: /html/body/div[2]/div/ul[2]/li/a/node() It returns something like this: #01
I have an HTML form as follow: <form method=POST action=http://> Username: <input type=text name=username
I have the follow HTML: <div id=menu> <ul class=menu> <li class=item-101><a href=/>Home</a></li> <li class=item-113><a
I am trying to follow Trees tutorial at: http://cslibrary.stanford.edu/110/BinaryTrees.html Here is the code I
I'm a postgresql user and I'm trying to follow this : http://www.postgresql.org/docs/current/interactive/sql-createtrigger.html CREATE TRIGGER

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.