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
|
 Rank: Addict
Joined: 7/19/2006 Posts: 815 Location: Århus, Denmark
|
I would go for: 'John&quot;s Doe'
|