LibXML (XPATH) and escape

F

Faith Greenwood

I am trying to escape single and double quotation marks in an XPATH
expression. Failing to escape the quotes produces an "Invalid
predicate" error.

Here's an example:

my $value="Dave's";
$value =~s/\'/\\\'/g;
my $search="//entry/owner/person[value/text()='$value']/../../this/
animal/value/text()";

However, this also produces the "Invalid predicate" error. I've tried
what the xpath language suggests by replacing a ' with '

my $value="Dave's";
$value =~s/\'/'/g;
my $search="//entry/owner/person[value/text()='$value']/../../this/
animal/value/text()";

This time, though, the search produces no results. (I know the
expression itself is valid as it works on $values that contain no
single or double quotes).

What is the correct way to escape quotation characters for XPath
expressions in perl?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,732
Latest member
ArronPalin

Latest Threads

Top