首页 > 解决方案 > 逻辑应用程序中的 XPath 根据其类型提取值

问题描述

我正在使用逻辑应用程序来剖析和重建入站 XML。我遇到的问题是 XML 的一部分并不总是以相同的顺序与相同数量的小节。所以我想知道是否可以根据类型返回值?即在此示例中,我想返回值 2,其中 2 并不总是第二个上下文。

 <ContextCollection>
  <Context>
    <Type>test1</Type>
    <Value>1</Value>
  </Context>
  <Context>
    <Type>test2</Type>
    <Value>2</Value>
  </Context>
  <Context>
    <Type>test3</Type>
    <Value>3</Value>
  </Context>

我已成功使用以下表达式xpath(xml(variables('XMLStripNameSpace')),'string(/*[name()="ContextCollection"]/*[name()="Context"][2]/*[name()="Value"])')

但这显然在 test2 是第三个时不起作用Context

标签: xmlxpathazure-logic-apps

解决方案


这个 XPath,

//Context[Type = "test2"]/Value

将选择 的元素的所有ValueContext元素Type test2


推荐阅读