For Each循环中的xpath [英] xpath in For Each loop
问题描述
$
我正在迭代XML文档,在eacj迭代中,我需要获取节点的值。
我为debatching指定了xpath, For-Each每次迭代都会给我以下文件
< wd:Order xmlns:wd =" mynamespace">
< span style ="white-space:pre"> < wd:OrderId> abc335< / wd:OrderId>
< / wd :订单>
我正在尝试提取orderId并将其分配给变量。
这是我的表达式: < br $> b $ b
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; ""Set_variable":{
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; "输入":{
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; "name":"myVariable","
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; "value":" @ {xpath(xml(item()),'/ * [local-name()= \" Order \"和namespace-uri()= \" mynamespace \\ \\"] / * [local-name()= \" OrderId \"
和namespace-uri()= \" mynamesspace \"]')}"
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; },b $ b &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; "runAfter":{},
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; "type":" SetVariable"
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }
但是,我没有看到 abc335 :
[{" ; $内容类型":"应用/ XML;字符集= UTF-8英寸,强>
的" $内容":" PHdkOkVtcGxveW1lbnRfU3RhdHVzIHhtbG5zOndkPSJ1cm46Y29tLndvcmtkYXkucmVwb3J0L1N1bl9MaWZlX0dSU19EZW1vZ3JhcGhpY3NfV1MiPkE8L3dkOkVtcGxveW1lbnRfU3RhdHVzPg =="}]
我做错了什么?我真的被卡住了...
谢谢!
Hi,
I am iterating over XML document, and on eacj iteration I need to extact the value of the node.
I specified xpath for debatching, For-Each on each iteration gives me the following document
<wd:Order xmlns:wd = "mynamespace">
<wd:OrderId>abc335</wd:OrderId>
</wd:Order>
I am trying to extract orderId and assign it to a variable.
Here is my expression:
"Set_variable": {
"inputs": {
"name": "myVariable",
"value": "@{xpath(xml(item()), '/*[local-name()=\"Order\" and namespace-uri()=\"mynamespace\"]/*[local-name()=\"OrderId\"
and namespace-uri()=\"mynamesspace\"]')}"
},
"runAfter": {},
"type": "SetVariable"
}
But, instead of abc335 I am seeing this:
[{"$content-type":"application/xml;charset=utf-8",
"$content":"PHdkOkVtcGxveW1lbnRfU3RhdHVzIHhtbG5zOndkPSJ1cm46Y29tLndvcmtkYXkucmVwb3J0L1N1bl9MaWZlX0dSU19EZW1vZ3JhcGhpY3NfV1MiPkE8L3dkOkVtcGxveW1lbnRfU3RhdHVzPg=="}]
What am I doing wrong? I am really stuck...
Thanks!
推荐答案
首先,你需要告诉解析器,这里只返回1个元素(你无法从xpath中判断出来)(使用first()函数)。
First of all, you need to tell the parser that there's only 1 element being returned here (which you cannot tell from an xpath) (using the first() function).
那么你还需要文本而不是元素(text()函数)
Then you also need the text and not the element (text() function)
另外:在逻辑应用程序中为for-each循环内部分配全局变量时要非常小心,除非你设置了"并发控制" ;为了真实并设定"并行度"到1。
Also: Please be very careful when assigning to a global variable inside a for-each loop in a Logic App, unless you have set "Concurrency Control" to true and set "Degree of Parallelism" to 1.
这是"SetVariable"的完整值表达式。操作:
Here is your full value expression for the "SetVariable" action:
@{first(xpath(xml(item()),'/*[local-name()=\"Order\" and namespace-uri()=\"mynamespace\"]/*[local-name()=\"OrderId\" and namespace-uri()=\"mynamespace\"]/text()'))}
Morten la Cour
这篇关于For Each循环中的xpath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!