4

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");
Rizier123
  • 58,877
  • 16
  • 101
  • 156
Rick
  • 591
  • 1
  • 9
  • 23

3 Answers3

3

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"); 
Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431
  • +1 Good answer addressing the real problem: embbeding a language into other language. Same kind of problems one could have with PHP and EmacScript. –  Dec 15 '10 at 18:54
3

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

Community
  • 1
  • 1
Jonathan Beebe
  • 5,241
  • 3
  • 36
  • 42
  • Please do not provide answers of other people in this way. [Or make it a CW](http://stackoverflow.com/privileges/community-wiki). We do not get upvotes for finding duplicates, nor for closevoting (which you cannot do yet). – Gordon Dec 15 '10 at 16:59
  • Thanks Gordon, I was unaware of the community wiki functionality. – Jonathan Beebe Dec 15 '10 at 17:51
  • 1
    actually, this is a pretty important point – prusswan Jul 21 '13 at 23:23
0

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

Igor Savinkin
  • 5,669
  • 8
  • 37
  • 69