开发者

XPATH query with single quote [duplicate]

开发者 https://www.devze.com 2023-01-30 13:25 出处:网络
This question already has answers here: 开发者_运维百科How to handle double quotes in string before XPath evaluation?
This question already has answers here: 开发者_运维百科 How to handle double quotes in string before XPath evaluation? (2 answers) Closed 7 years ago.

Anyone have any ideas how to resolve this? The single quote is throwing me for a loop.

$nodes = $xml->xpath("//item[contains(@catalog,'Billy's Blogs')]/title");

I've tried to escape it in various ways, all throwing errors:

$nodes = $xml->xpath("//item[contains(@catalog,'Billy\'s Blogs')]/title");
$nodes = $xml->xpath("//item[contains(@catalog,'Billy's Blogs')]/title");


Use whatever way there is in your language (I don't know PHP) to escape the quote character inside a quoted string, something like this:

$nodes = $xml->xpath("//item[contains(@catalog,\"Billy's Blogs\")]/title"); 


As salathe answered here, you cannot escape an apostrophe in XPath.


How about using quote along with ' and "? See example in here. notes = 'New Lapytop&quots ;USB" MP3 player&quot'

0

精彩评论

暂无评论...
验证码 换一张
取 消