You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

多条件XML文本提取的XPath规则需求(无代码实现)

符合需求的XPath单规则方案

最终单条XPath表达式

//P[
  @countries='AR' 
  or (not(@countries) and (ancestor::*[@countries='AR'] or not(ancestor::*[@countries])))
]

表达式拆解(对应三类提取条件)

  • @countries='AR':直接匹配自身countries属性为“AR”的<P>元素,对应条件1
  • not(@countries) and ancestor::*[@countries='AR']:匹配自身无countries属性,但存在祖先元素的countries属性为“AR”的<P>元素,对应条件2
  • not(@countries) and not(ancestor::*[@countries]):匹配自身及所有祖先元素均无countries属性的<P>元素,对应条件3

简化紧凑写法(逻辑等价)

如果需要更简洁的表达式,可合并后两个条件的公共逻辑:

//P[@countries='AR' or not(@countries) and (ancestor::*[@countries='AR'] or not(ancestor::*[@countries]))]

内容的提问来源于stack exchange,提问作者Paul

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 03:45:35