2
如何编写一个xpath来选择一个节点,其文本中包含特殊字符,例如'哪一种是无效的inxpath?如何编写xpath以选择其文本包含特殊字符(如apostorophe)的节点?
<Nodes><Node><Text>General Marketing'</Text><Nodes><Node><Text>Brochures</Text></Node><Node><Text>Value-Added</Text><Nodes><Node><Text>About Henderson</Text></Node><Node><Text>Own the World</Text></Node></Nodes></Node></Nodes></Node></Nodes>
和
var branchName = "General Marketing'";
var xPath = String.Format("/Nodes/Node[Text = '{0}']", branchName);
以上的XPath失败,因为XPATH包含以下内容:
/Nodes/Node[Text = 'General Marketing'']
正如你可以看到有2个apostorophes。
从我的测试到目前为止,它只有问题'。不确定是否有任何其他可能有问题的特殊字符?
所以我想我需要修改我的xpath是别的东西。
我试过以下,但没有奏效:
var xPath = String.Format("/Nodes/Node[Text = \"{0}\"]", branchName);
希望这个问题是清楚的。
谢谢,