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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,142
Latest member
DewittMill
Top