Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

my xmlnodelist contains below string
<rows><row rowID=\"1\"><ValueColumn>value1\"</ValueColumn></row></rows>


string a=
"rows/row[ValueColumn=\"value1\"\"]"


XmlNodeList optionNodes = _optionNode.SelectNodes(a);

getting error ,invalid token.

What I have tried:

"/*/rows/row[ValueColumn=\"value4witha\"\"]"

not worked
Posted
Updated 21-Mar-19 7:18am
Comments
Richard MacCutchan 18-Mar-19 6:58am    
Yes, because of the extra quote character after value1.

1 solution

Use single quotes around the value you're looking for:
"/*/rows/row[ValueColumn='value1\"']"

NB: If you need to search for values which contain a mixture of single and double quotes, things become much more complicated. You basically have to split the strings up so that each part only contains one type of quote, use the other type of quote to start and end that string, and use concat to combine them. For example:
XML
<row><ValueColumn>I'd like it if "This" was easier!</ValueColumn></row>
"row[ValueColumn=concat(\"I'd like it if \", '\"This\" was easier!')]"

XPath 2.0 apparently makes this easier by letting you escape quotes by doubling them up:
"row[ValueColumn=\"I'd like it if \"\"This\"\" was easier!\"]"
"row[ValueColumn='I''d like it if \"This\" was easier!']"
Unfortunately, .NET has never implemented XPath 2.0, so you this won't work in C#.

c# - Using quotes in Xpath - Stack Overflow[^]
 
Share this answer
 
Comments
Maciej Los 22-Mar-19 10:08am    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900