none
xpath in For Each loop RRS feed

  • Question

  • 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!
    Wednesday, February 27, 2019 7:09 PM

All replies

  • 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).

    Then you also need the text and not the element (text() function)

    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.

    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

    Wednesday, February 27, 2019 7:49 PM