【发布时间】:2020-11-17 14:35:43
【问题描述】:
我正在尝试搜索 XML 文件以查找匹配项,但我不想搜索每个元素。 not 语句不起作用所以我做错了什么? (之前没有使用过 xpath)
我想排除元素“product_image”和“category_image”
$items = $xml->xpath("//item/*[contains(text(), '$find')][not(product_image, category_image)]/parent::*");
<item>
<id>108</id>
<title>Big car</title>
<cat>SUV</cat>
<color>black</color>
<product_image>CUa6wVWiHAXHI68mtbUFsNj-F05lDM62_250x250.png</product_image>
<category_image>comeUYh5I9Juz2hr1NBZCSx9cKSgXXNA_250x250.png</category_image>
</item>
[...]
【问题讨论】:
-
你当前/想要的输出是什么?
-
它会搜索每一个元素,这不是我想要的。 NOT 部分不起作用
-
您希望它如何工作?什么条件?
-
很好地搜索 ITEM 的每个子项,但不是 2 个字段(*_image)
-
什么是
[contains(text(), '$find')]谓词?应该怎么做?