XPath (v1) не содержит возможности кодирования выражений.
Если у вас есть только двойные кавычки ИЛИ, вы можете использовать выражения типа
//review[@name="Bob Pizza"]
//review[@name='"Pizza" Pam']
Но если у вас есть BOTH, например [Fred "Fancy Pizza" ], тогда вы должны использовать что-то вроде этого Escaping Strings в XPath (С++) для генерации
//review[@name=Concat("Fred ",'"Fancy Pizza"')]
Кто-нибудь имеет функцию в С# для этого?
Некоторые близкие ссылки
- Используйте библиотеку MVP.XML и XPathVariable (очень хорошее решение, но немного тяжеловесный для моих нужд).
- Не кодирует, где присутствуют оба "и"
- Добавляет больше аргументов в операцию Concat, чем необходимо например вернется //review [@name = concat ('Fred', '' ',', '' ',' Fancy Pizza ',' '', '')]
EDIT: несколько ответов предложили экранировать "с помощью '
и" с помощью "
, но, хотя это имеет смысл, он не работает, попробуйте его с помощью фрагмента XML:
<review name="Bob Pizza"/>
и xpath
//review[@name='Bob's Pizza']