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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:00:04+00:00 2026-06-14T17:00:04+00:00

I can’t figure out how to search for text containing single quotes using XPATHs.

  • 0

I can’t figure out how to search for text containing single quotes using XPATHs.

For example, I’ve added a quote to the title of this question. The following line

$x("//*[text()='XQuery looking for text with 'single' quote']")

Returns an empty array.

However, if I try the following

$x("//*[text()=\"XQuery looking for text with 'single' quote\"]")

It does return the link for the title of the page, but I would like to be able to accept both single and double quotes in there, so I can’t just tailor it for the single/double quote.

You can try it in chrome’s or firebug’s console on this page.

  • 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-14T17:00:06+00:00Added an answer on June 14, 2026 at 5:00 pm

    Here’s a hackaround (Thanks Dimitre Novatchev) that will allow me to search for any text in xpaths, whether it contains single or double quotes. Implemented in JS, but could be easily translated to other languages

    function cleanStringForXpath(str)  {
        var parts = str.match(/[^'"]+|['"]/g);
        parts = parts.map(function(part){
            if (part === "'")  {
                return '"\'"'; // output "'"
            }
    
            if (part === '"') {
                return "'\"'"; // output '"'
            }
            return "'" + part + "'";
        });
        return "concat(" + parts.join(",") + ")";
    }
    

    If I’m looking for I'm reading "Harry Potter" I could do the following

    var xpathString = cleanStringForXpath( "I'm reading \"Harry Potter\"" );
    $x("//*[text()="+ xpathString +"]");
    // The xpath created becomes 
    // //*[text()=concat('I',"'",'m reading ','"','Harry Potter','"')]
    

    Here’s a (much shorter) Java version. It’s exactly the same as JavaScript, if you remove type information. Thanks to https://stackoverflow.com/users/1850609/acdcjunior

    String escapedText = "concat('"+originalText.replace("'", "', \"'\", '") + "', '')";!
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Can't seem to figure out what's wrong with the simple getJSON call below. It's
Can I authenticate with just Google account username and password instead of using OAuth?
Can PHP PDO extension bind nested objects automatically ? I mean using foreign key
Can anyone suggest how to underline the title of a UIButton ? I have
Can anyone give me an example of how to return the following json simply
Can any one help me in sorting this out in sed/awk/perl Input file Start
Can someone help me with a command line instruction to drop a single MAMP
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Can anyone provide an example of how to retrieve captions for YouTube video? Based

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.