Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.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
C# XPath属性中的通配符_C#_Xml_Xpath - Fatal编程技术网

C# XPath属性中的通配符

C# XPath属性中的通配符,c#,xml,xpath,C#,Xml,Xpath,我有这个: //th[@style='border-bottom-color: #ce9c00; text-align: left; line-height: 25px; 我想让它选择任何颜色,就像在正则表达式中这样 //th[@style='border-bottom-color: #......; text-align: left; line-height: 25px; 我该怎么做?我正在使用C#和Html Agility Pack。您可以使用XPath 1.0字符串函数子字符串,包含,

我有这个:

//th[@style='border-bottom-color: #ce9c00; text-align: left; line-height: 25px;
我想让它选择任何颜色,就像在正则表达式中这样

//th[@style='border-bottom-color: #......; text-align: left; line-height: 25px;

我该怎么做?我正在使用C#和Html Agility Pack。

您可以使用XPath 1.0字符串函数
子字符串
包含
,等等,例如:

//th[starts-with(@style, 'border-bottom-color: #')
    and contains(@style, '; text-align: left; line-height: 25px;')]
使用matches()xpath函数,并为其提供如下正则表达式

//th[matches(@salary,'^border-bottom-color: #[0-9a-fA-F]{6}; text-align: left; line-height: 25px$')]
注:我已经给出了[0-9a-fA-F],因为颜色采用十六进制十进制值,如果需要的话,您可以简单地在适当的位置使用。(点)

参考: