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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:17:01+00:00 2026-05-18T05:17:01+00:00

So right now if I have something like this: //div[@class=’artist’]/p[x]/text() x can either be

  • 0

So right now if I have something like this:

//div[@class='artist']/p[x]/text()

x can either be 3 or 4, or maybe even a different number. Luckily, if what I am looking for is not in 3, I can just check for null and go on until I find text. The issue is I would rather know I’m going to the right element every time. So I tried this:

div[@class='people']/h3[text()='h3 text']/p/text()

since there will always be a <p> right after <h3>h3 text</h3>. However this never returns anything, and usually results in an error. If I remove /p I will get ‘h3 text’ returned.

Anyway, how do I get that <p> directly after <h3>?

BTW, I’m using HTMLCleaner in Java for this.

  • 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-18T05:17:01+00:00Added an answer on May 18, 2026 at 5:17 am

    By default when you don’t specify an axis you get the child:: axis, which is why the / operator seems to descend the DOM tree child by child. There is an implied child:: after each slash.

    In your case you don’t want to find a child of the <div>, you want to find a sibling of it. A sibling is an element at the same nesting level. Specifically, you should use the following-sibling:: axis.

    div[@class='people']/h3[text()='h3 text']/following-sibling::p/text()
    

    XPath Axes

    Axes are an advanced feature of XPath. They are one of the features that make XPath especially powerful.

    You’re already familiar with one other axis, though you may not have realized it: the @ symbol is shorthand for attribute::. When you write @href you’re really saying attribute::href, as in look for an attribute called “href” instead of a child.

    Axes, eh? Shorthand, eh? Tell me more, you say? OK!

    • . and .. are shorthand for the more verbose self::node() and parent::node(), respectively. You could use the longer forms if you wished.

    • The // operator you commonly see as //p or body//a has a hidden descendant-or-self::node() between the slashes. //p is shorthand for /descendant-or-self::node()/p.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now I have something like this in NHibernate: Expression.Like(property, value, MatchMode.Anywhere) and that
I have a template like this: <script id=notesTemplate type=text/html> <li class=Note> <div class=NoteDate data-bind=style:
I have 3 expand divs with the same strcuture. Something like: <div class=expand> <h3
I'm doing something like this: maxDim = 100; $('div.images').html('<img class=pull src='+imgs[img_i]+' />'); $('img.pull').each(function(i){ if(
Right now I have a function, in a class that is used to listen
Right now I have a link that causes a hidden div to appear when
Right now I have this SQL query which is valid but always times out:
Suppose a HTML like this: <div id=header> <span class=title>Title</span> <!-- more spans and other
Let's say I have messages on my page: <div class=message one>Here is some text.</div>
Good day! I right now have a function the drags an element from a

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.