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

如何在Power Automate中从HTTP XML响应获取id字段

Power Automate中提取XML响应id字段的正确方法

目标XML响应

<?xml version="1.0" encoding="UTF-8"?>
<ServiceResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://test.qg.apps.test.com/qps/xsd/3.0/was/report.xsd">
  <responseCode>SUCCESS</responseCode>
  <count>1</count>
  <data>
    <Report>
      <id>3505012</id>
    </Report>
  </data>
</ServiceResponse>

你之前尝试的错误表达式及问题

  • 字符串截取表达式:@{slice(outputs('createreportxml'), add(nthIndexOf(outputs('createreportxml'), '&gt;', 9), 1), nthIndexOf(outputs('createreportxml'), '&lt;', 10))}
    问题:依赖标签出现的索引位置,一旦XML结构变动(比如新增字段、空格调整),索引就会失效,稳定性极差,且手动数索引极易出错。
  • XPath表达式:xpath(xml(outputs('@{outputs('createreportxml')}'))), 'string(/ServiceResponse/data/Report/id/text())'
    问题:语法错误,嵌套的@{}属于多余写法,同时存在括号配对错误,不符合xpath函数的参数格式要求。

正确的提取方法

直接使用XPath表达式,这是处理XML最可靠的方式,正确语法如下:

xpath(xml(outputs('createreportxml')), 'string(/ServiceResponse/data/Report/id)')

或者更严谨地提取文本节点:

xpath(xml(outputs('createreportxml')), 'string(/ServiceResponse/data/Report/id/text())')

说明

  • xml(outputs('createreportxml')):将HTTP返回的XML字符串转换为Power Automate可识别的XML对象。
  • xpath(...):通过XPath语法精准定位节点,string()函数直接提取节点的文本值。
  • 路径/ServiceResponse/data/Report/id完全匹配XML的层级结构,只要节点层级不变,就能稳定提取值,不受格式微调影响。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.06 08:50:27