gpt4 book ai didi

html - 如何使用 XPath 选择包含单引号的元素?

转载 作者:行者123 更新时间:2023-12-02 06:13:08 24 4
gpt4 key购买 nike

我想使用 XPath 选择此元素:

<a href="#" onClick="onViewDocument('2016', '1');">2016</a>

到目前为止我有这个:

//a[@onClick='onViewDocument('2016', '1');']

我需要转义 20161 周围的单引号吗?

最佳答案

最简单的通常是使用 ' 的替代品或" ,取决于字符串文字周围已经使用的内容。

如果这不可行,另一种方法是使用 &apos;对于 ' (单引号):

//a[@onClick='onViewDocument(&apos;2016&apos;, &apos;1&apos;);']

请注意,您可以使用&quot;对于 " (双引号)。

引用: XML Path Language (XPath) Version 1.0 :

XPath expressions often occur in XML attributes. The grammar specified in this section applies to the attribute value after XML 1.0 normalization. So, for example, if the grammar uses the character <, this must not appear in the XML source as < but must be quoted according to XML 1.0 rules by, for example, entering it as &lt;. Within expressions, literal strings are delimited by single or double quotation marks, which are also used to delimit XML attributes. To avoid a quotation mark in an expression being interpreted by the XML processor as terminating the attribute value the quotation mark can be entered as a character reference (&quot; or &apos;). Alternatively, the expression can use single quotation marks if the XML attribute is delimited with double quotation marks or vice-versa.

关于html - 如何使用 XPath 选择包含单引号的元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37403236/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com