【问题标题】:XPath for namespaced XML attributes in Power Automate?Power Automate 中命名空间 XML 属性的 XPath?
【发布时间】:2021-03-09 01:43:04
【问题描述】:

我每天通过电子邮件收到一个 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 查询以该基金名称为条件?

【问题讨论】:

    标签: xml xpath xml-namespaces power-automate


    【解决方案1】:

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

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

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

    这将选择fund 元素的fund_name 属性值为'Fund Name'prices 元素子元素的所有base_price 元素子元素,而不考虑fund_name 属性上的命名空间。

    另见

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-24
      • 2014-04-19
      相关资源
      最近更新 更多