Search code examples
azurexpathazure-logic-apps

Logic app xpath function return the result in encoded format


I have a an xml code that looks similar to this:

<?xml version="1.0" encoding="UTF-8"?>
<part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="payload">
    <process xmlns="http://xmlns.oracle.com/CommonBaswareHTTPWrapperProvider/CommonBasware_HTTPWrapperProviderBPEL">
        <BaswareRequest xmlns="http://xmlns.oracle.com/CommonBaswareHTTPWrapperProvider/BaswareRequest">
            <BOName>yy</BOName>
            <FileName>xx.xml</FileName>
            <Action>SEND</Action>
            <BOMessage>
                <DocumentElement xmlns="">
                    <Item>
                        <Text_1>123</Text_1>
                        <Text_2>123 CIO Office HOF</Text_2>
                        <Text_3>SWEDEN</Text_3>
                        <Text_4>3650</Text_4>
                        <Text_5>SWEDEN</Text_5>
                        <Text_6>True</Text_6>
                        <Text_EN />
                        <Active>True</Active>
                        <Company>001</Company>
                    </Item>
                </DocumentElement>
            </BOMessage>
        </BaswareRequest>
    </process>
</part>

I would Like to extract the element BOMessage with all its content and use it later in the code.

Inside the Logic App, I have created a compose action and written this code inside it:

xpath(xml(triggerBody()), '//*[local-name()="BOMessage"]')

The output of this action return a strange encoded code:

[
  {
    "$content-type": "application/xml;charset=utf-8",
    "$content": "PEJPTWVzc2FnZSB4bWxucz0iaHR0cDovL3htbG5zLm9yYWNsZS5jb20vQ29tbW9uQmFzd2FyZUhUVFBXcmFwcGVyUHJvdmlkZXIvQmFzd2FyZVJlcXVlc3QiPg0KICAgICAgICAgICAgICAgIDxEb2N1bWVudEVsZW1lbnQgeG1sbnM9IiI+DQogICAgICAgICAgICAgICAgICAgIDxJdGVtPg0KICAgICAgICAgICAgICAgICAgICAgICAgPFRleHRfMT4xMjM8L1RleHRfMT4NCiAgICAgICAgICAgICAgICAgICAgICAgIDxUZXh0XzI+MTIzIENJTyBPZmZpY2UgSE9GPC9UZXh0XzI+DQogICAgICAgICAgICAgICAgICAgICAgICA8VGV4dF8zPlNXRURFTjwvVGV4dF8zPg0KICAgICAgICAgICAgICAgICAgICAgICAgPFRleHRfND4zNjUwPC9UZXh0XzQ+DQogICAgICAgICAgICAgICAgICAgICAgICA8VGV4dF81PlNXRURFTjwvVGV4dF81Pg0KICAgICAgICAgICAgICAgICAgICAgICAgPFRleHRfNj5UcnVlPC9UZXh0XzY+DQogICAgICAgICAgICAgICAgICAgICAgICA8VGV4dF9FTiAvPg0KICAgICAgICAgICAgICAgICAgICAgICAgPEFjdGl2ZT5UcnVlPC9BY3RpdmU+DQogICAgICAgICAgICAgICAgICAgICAgICA8Q29tcGFueT4wMDE8L0NvbXBhbnk+DQogICAgICAgICAgICAgICAgICAgIDwvSXRlbT4NCiAgICAgICAgICAgICAgICA8L0RvY3VtZW50RWxlbWVudD4NCiAgICAgICAgICAgIDwvQk9NZXNzYWdlPg=="
  }
]

I tried to surround the xpath function with xml() function and base64ToString() and decodeBase64() but all of them are returning errors and doesn't seems to work.

Any idea for how to solve this issue?


Solution

  • This is normal. When you try accessing the first element of the xpath output array, you'll be happy with the result. Try using the following in your 'Compose' action and you'll be OK:

    xpath(xml(triggerBody()), '//*[local-name()="BOMessage"]')?[0]