Power Automate 中命名空间 XML 属性的 XPath?

问题描述

我每天都通过电子邮件收到一个 XML 文件,我正在尝试编写 Flow / Power Automate 来解析 XML,从中获取 3 个变量,并将它们附加到 Excel 中的表格中。 XML 文件具有以下结构,其加载到具有标识符 InputXML

查询
<?xml version="1.0" encoding="UTF-8"?>
<ifir:inter_fund_investor_report ifir:creation_date_time="2021-02-24T21:16:01"
                                 ifir:report_id="102068045"
                                 xmlns:ifir="nzl:org:fsc:XMLSchema:InterfundInvestorReport:v2.0">
  <investor ifir:investor_name="client name" ifir:investor_id="client123">
    <fund ifir:currency="USD" ifir:fund_valuation_date="2021-02-23" ifir:fund_name="Fund Name" ifir:fund_id="fundcode" ifir:is_fund_a_PIE="Y">      
      <balances>        
        <investor_units_held>123456</investor_units_held>
        <total_units_on_issue>999999999</total_units_on_issue>
      </balances>
      <prices>
        <base_price>1.060</base_price>
        <entry_price>1.0650</entry_price>
        <exit_price>1.055</exit_price>
      </prices>
      <totals ifir:fund_allocation_date="2021-02-23"/>
    </fund>
  </investor>
</ifir:inter_fund_investor_report>

我已经能够通过使用表达式获得 base_price

xpath(xml(outputs('InputXML')),'//base_price')

但是我无法从 XML 中取出 fund_namefund_valuation_date

有人能帮我用 XPath 表达式来获得这两个吗? XML 文件目前只有一个 fund_name,但将来可能会有更多,所以如果可能的话,我还应该使 base_price 查询以该基金名称为条件?

解决方法

Power Automate documentation for XML 中没有表明它支持命名空间 XML 组件的 XPath 查询。

您可以通过测试属性的本地名称来解决这样的限制:

//fund[@*[local-name()='fund_name' and .='Fund Name']]/prices/base_price

这将选择 base_price 属性值为 prices 的那些 fund 元素的 fund_name 元素子元素的所有 'Fund Name' 元素子元素,而不管fund_name 属性。

另见