Single Quote in XPath query - help! Options
Sunday Ironfoot
Posted: Friday, November 14, 2008 4:39:56 PM
Rank: Newbie

Joined: 10/8/2007
Posts: 21
Could someone tell me what's wrong with the following...

string xpathQuery = "//keywords/keyword[starts-with(translate(string(.),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'John's Doe')]";
XPathNodeIterator iterator = umbraco.library.GetXmlNodeByXPath(xpathQuery);

It currently throws an XPathException (message: ''//keywords/keyword[starts-with(translate(string(.),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'John's Doe')]' has an invalid token.'), so I assume it'll have something to do with the single quote in 'John's Doe'. So my question is really, how do I escape single quotes in XPath queries?

I've tried the following...

'John\'s Doe'
'John's Doe'
'John"s Doe'

which don't seem to work. The XML looks like this...

<node id="1076" ....snip.... nodeTypeAlias="Resource" path="-1,1041,1075,1076">
<data alias="Title">Resource 2</data>
<data alias="Authors">John Smith</data>
<data alias="URL">http://www.example.com/home.aspx</data>
<data alias="Keywords">
<keywords>
<keyword>Orange</keyword>
<keyword>Pear</keyword>
<keyword>John's Doe</keyword>
</keywords>
</data>
</node>

Dominic Pettifer
mortenbock
Posted: Friday, November 14, 2008 5:36:25 PM

Rank: Addict

Joined: 7/19/2006
Posts: 815
Location: Århus, Denmark
I would go for:

'John&amp;quot;s Doe'


Morten Bock - Level 2 certified - MVP 2008/2009 - My danish blog with a few english posts

Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.