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

如何在Power Automate中获取嵌套JSON的通配符匹配元素值?

在Power Automate中通过通配符匹配XML父元素获取嵌套值

核心解决方案:利用XPath的starts-with和local-name()函数匹配动态父元素

既然你已经将目标结构转成XML并存入varXML,且在循环中处理每个节点,直接用XPath的通配符逻辑就能匹配所有以f开头的父元素,再提取子节点值。

具体表达式写法

在「Compose - product_name」及其他同类步骤中,使用以下格式的表达式:

获取product_name

xpath(items('Apply_to_each'), 'string(//body/*[starts-with(local-name(), "f")]/product_name)')

获取service_name

xpath(items('Apply_to_each'), 'string(//body/*[starts-with(local-name(), "f")]/service_name)')

获取link

xpath(items('Apply_to_each'), 'string(//body/*[starts-with(local-name(), "f")]/link)')

关键细节说明

  • local-name():提取XML元素的名称(不带命名空间),用来判断父元素是否以f开头
  • starts-with(local-name(), "f"):精准匹配所有名称以f开头的父元素
  • string():将XPath返回的节点集转换为字符串,直接拿到子元素的文本值
  • 如果body下存在多个以f开头的元素,需指定取第几个,比如取第一个就加[1]:
    xpath(items('Apply_to_each'), 'string(//body/*[starts-with(local-name(), "f")][1]/product_name)')
    

测试建议

先添加一个临时Compose步骤,输出xpath(items('Apply_to_each'), '//body/*[starts-with(local-name(), "f")]')的结果,确认是否正确匹配到目标父元素,再提取子节点值会更稳妥。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.30 21:22:04