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

xidel提取Pubmed节点时报invalid type for union错误如何解决

错误原因

XPath 中的 | 是节点集联合运算符,只能作用于节点类型的集合,你写的两个表达式返回的都是 join() 生成的字符串,不是节点,所以触发类型错误 err:XPTY0004。

正确实现方式

核心逻辑是先筛选出两类目标节点,再对每个节点统一做内容提取,不要对处理后的字符串结果做联合。
可直接运行的命令如下:

xidel -s -e '//*[self::PubmedArticle or self::BookDocument]/join((if (name()="PubmedArticle") then MedlineCitation/PMID else PMID, normalize-space(outer-xml())), x:cps(9))' 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=pubmed&retmode=xml&id=22259814,26978846'

上述表达式的逻辑:

  1. 先用 //*[self::PubmedArticle or self::BookDocument] 筛选出所有 PubmedArticle 和 BookDocument 节点,这一步是对节点做筛选,完全符合 XPath 语法要求
  2. 对每个筛选出的节点做判断:如果是 PubmedArticle 就取子节点 MedlineCitation/PMID,如果是 BookDocument 就直接取子节点 PMID
  3. 把 PMID 和节点格式化后的 XML 内容用制表符拼接输出,和你之前两条命令的输出结果完全一致

如果你偏好使用 | 联合节点集的写法,效果完全相同:

xidel -s -e '(//PubmedArticle | //BookDocument)/join((if (name()="PubmedArticle") then MedlineCitation/PMID else PMID, normalize-space(outer-xml())), x:cps(9))' 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=pubmed&retmode=xml&id=22259814,26978846'

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.07 14:24:02