Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html XPath选择具有类通配符的元素?_Html_Xml_Xpath - Fatal编程技术网

Html XPath选择具有类通配符的元素?

Html XPath选择具有类通配符的元素?,html,xml,xpath,Html,Xml,Xpath,是否存在使用通配符选择项的可能XPath?例如,我尝试了//img[@class='poly*']来选择这些img元素 <img class="poly x1" title="title1"> <img class="poly x2" title="title2"> <img class="poly x3" title="title3"> 但是它不起作用。*在XPath中不是通配符,所以 //img[@class='poly *'] 将所有img

是否存在使用通配符选择项的可能XPath?例如,我尝试了
//img[@class='poly*']
来选择这些
img
元素

<img class="poly x1" title="title1"> 
<img class="poly x2" title="title2"> 
<img class="poly x3" title="title3"> 


但是它不起作用。

*
在XPath中不是通配符,所以

//img[@class='poly *']
将所有
img
元素与
class
属性值完全相同的
poly*
-字面上以
*
字符结尾

您可以使用

//img[starts-with(@class,'poly')]
或者更强大的习惯用法,允许
poly
出现在
属性值的任何位置,而不匹配
多态性
等。错误:

//img[contains(concat(' ',@class,' '), ' poly ')]
注意:XPath2.0有一个支持正则表达式的
matches()
函数