I'm trying to use SelectNodes where an attribute is containing a text with apostrophes
The attribute is oor:path and the node looks like this:
<item oor:path="/org.openoffice.Office.Histories/Histories/org.openoffice.Office.Histories:HistoryInfo['PickList']/OrderList">
I have tried with this code (and failed)...
XmlNodeList xnList = xml.SelectNodes("/oor:items/item[contains(@oor:path, '['PickList']/OrderList')]", nsMgr);
Please Help!
// Anders
The '
entities are resolved into single quotes before the XPath parser can see them. Therefore, from its point of view, they cannot be distinguished from "real" single quotes.
You can delimit the argument to contains()
with escaped double quotes and use single quotes in the expression:
XmlNodeList xnList = xml.SelectNodes(
"/oor:items/item[contains(@oor:path, \"['PickList']/OrderList\")]", nsMgr);
Or, alternatively, using a verbatim string literal:
XmlNodeList xnList = xml.SelectNodes(
@"/oor:items/item[contains(@oor:path, ""['PickList']/OrderList"")]", nsMgr);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With