我有一个 XML:
<entities>
<entity attribute="attribute-value-1 attribute-value-2">value1</entity>
<entity attribute="attribute-value-5 attribute-value-7 attribute-value-8">value2</entity>
</entities>
Run Code Online (Sandbox Code Playgroud)
如何使用 XPath 选择属性值为 的实体"attribute-value-7"?
您必须小心避免无意中匹配超字符串,例如“attribute-value-77”或“wrong-attribute-value-7”。
使用常用的习惯用法来匹配 HTML@class属性:
//entity[contains(concat(' ', normalize-space(@attribute), ' '),
' attribute-value-7 ')]
Run Code Online (Sandbox Code Playgroud)
//entity[tokenize(@attribute,'\s+')='attribute-value-7']
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
778 次 |
| 最近记录: |