Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.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_Bash_Xpath_Wildcard - Fatal编程技术网

Html 如何在Xpath上使用通配符

Html 如何在Xpath上使用通配符,html,bash,xpath,wildcard,Html,Bash,Xpath,Wildcard,该字符串有一个静态部分aligncenter wp图像-和一个动态部分“我想在这里做的是连接所有的posible” 在bash中是这样的: cover: $main//*[has-class("aligncenter wp-image-121146 size-large")]//img cover: $main//img[has-class("aligncenter wp-image-121146 size-large")] 如何在Xpath中实现这一点?我认为这将起作用: "

该字符串有一个静态部分aligncenter wp图像-和一个动态部分“我想在这里做的是连接所有的posible”

在bash中是这样的:

    cover: $main//*[has-class("aligncenter wp-image-121146 size-large")]//img
    cover: $main//img[has-class("aligncenter wp-image-121146 size-large")]

如何在Xpath中实现这一点?

我认为这将起作用:

"aligncenter wp-image-"*
这可能更健壮,没有尝试过很多
,看起来您希望类的顺序是这样的:

'//E[@class="aligncenter" and contains(concat(" ", @class, "wp-image-"), " C ")]'
但我还没有测试过,不管怎样,这都会对您有所帮助:


我认为这会奏效:

"aligncenter wp-image-"*
这可能更健壮,没有尝试过很多
,看起来您希望类的顺序是这样的:

'//E[@class="aligncenter" and contains(concat(" ", @class, "wp-image-"), " C ")]'
但我还没有测试过,不管怎样,这都会对您有所帮助:


由于您没有提供示例XML/HTML,因此没有足够的信息为该问题提供准确的XPath解决方案,并且两个尝试的XPath表达式(如果它们确实是)都无效

为了回答这个问题,您不能像XPath 1.0那样使用通配符,XPath 1.0是最广泛实现的XPath版本。但是您可以使用
contains()
starts-with()
函数。后者似乎更适合这种特殊情况。例如,以下XPath返回文档中的所有
img
元素,其中
class
属性值以子字符串“aligncenter wp image-”开头:

'//E[contains(concat(" ", @class, "aligncenter wp-image-"), " C ")]'

由于您没有提供示例XML/HTML,因此没有足够的信息为该问题提供准确的XPath解决方案,并且两个尝试的XPath表达式(如果它们确实是)都无效

为了回答这个问题,您不能像XPath 1.0那样使用通配符,XPath 1.0是最广泛实现的XPath版本。但是您可以使用
contains()
starts-with()
函数。后者似乎更适合这种特殊情况。例如,以下XPath返回文档中的所有
img
元素,其中
class
属性值以子字符串“aligncenter wp image-”开头:

'//E[contains(concat(" ", @class, "aligncenter wp-image-"), " C ")]'

您需要说明XPath的哪个版本。在XPath2.0(或3.0或3.1)中,可以将
matches()
函数与正则表达式一起使用。在1.0中,您只有
start-with()
contains()
函数。您需要说明XPath的哪个版本。在XPath2.0(或3.0或3.1)中,可以将
matches()
函数与正则表达式一起使用。在1.0中,只有
start-with()
contains()
函数。