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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:59:26+00:00 2026-05-14T06:59:26+00:00

How do I use something similar to the example below, but with the opposite

  • 0

How do I use something similar to the example below, but with the opposite result, i.e items that do not contain (default) in the text.

<test>
     <item>Some text (default)</item>
     <item>Some more text</item>
     <item>Even more text</item>
</test>

Given this

//test/item[contains(text(), '(default)')]

would return the first item. Is there a not operator that I can use with contains?

  • 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-14T06:59:27+00:00Added an answer on May 14, 2026 at 6:59 am

    Yes, there is:

    //test/item[not(contains(text(), '(default)'))]

    Hint: not() is a function in XPath instead of an operator.


    An alternative, possibly better way to express this is:

    //test/item[not(text()[contains(., '(default)')])]

    There is a subtle but important difference between the two expressions (let’s call them A and B, respectively).

    Simple case: If all <item> only have a single text node child, both A and B behave the same.

    Complex case: If <item> can have multiple text node children, expression A only matches when '(default)' occurs in the first of them.

    This is because text() matches all text node children and produces a node-set. So far no surprise. Now, contains() accepts a node-set as its first argument, but it needs to convert it to string to do its job. And conversion from node-set to string only produces the string value of the first node in the set, all other nodes are disregarded (try string(//item) to see what I mean). In the simple case this exactly what happens as well, but the result is not as surprising.

    Expression B deals with this by explicitly checking every text node individually instead of only checking the string value of the whole <item> element. It’s therefore the more robust of the two.

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

Sidebar

Related Questions

I need to use something like get_or_create() but the problem is that I have
Is there a method similar to equals() that expresses not equal to? An example
Does anyone know anyway to use something similar to polygon.getKml() except for the current
I am looking for a way to use a UILabel (or something similar) to
What is the proper way to use mysql TIMEDIFF, (or something similar)? In database
I'm trying to use something along the lines of unexpand -t 4 *.php but
I've searched for similar questions to mine here, but haven't found a thread that
In nearly every model, I end up writing code similar to the below example
I understand that are similar question on StackOverflow about this problem, but none of
I have a controller uri hierarchy similar to the example below. @RequestMapping(value=company/{id}) public abstract

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.