0

I have a Logic app (LA) that have an http trigger. To the LA, I send a SOAP request similar to this:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <SOAP-ENV:Header xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"></SOAP-ENV:Header>
  <SOAP-ENV:Body>
    <tns:Order xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:tns="http://test.com">
      <name>AAAA</name>
      <id>1234</id>
      <OrderType>new</OrderType>
    </tns:Order>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

I want to create another action in the LA that extract the Envelope body to me. i.e. I want to only get this:

<tns:Order xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:tns="http://test.com">
    <name>AAAA</name>
    <id>1234</id>
    <OrderType>new</OrderType>
</tns:Order>

I tried to have a compose action with the following function:

xpath(triggerBody(), '/*[local-name()=''Envelope'']/*[local-name()=''Body'']/*[local-name=''Order'']')

as you can see here: enter image description here

but this reutn to me an error: enter image description here

Any idea for how to solve this problem? I have tried to remove all the namespaces and it seems that it works but not when having namespaecs

ibda
  • 376
  • 3
  • 15

2 Answers2

1

Your issue with the null is a bit perplexing and hard for me to decipher and fix because receiving that error tells me you're not quite reading the incoming request properly (or something) but, if I load your XML into a variable and then extract the contents of tns:Order, I can get it to work and this approach doesn't require you to traverse down the hierarchy using a fully qualified approach.

Flow

Flow

This is the expression in the second step ...

first(xpath(xml(variables('XML')), '//*[local-name()="Order"]'))

Result

Result

Skin
  • 9,085
  • 2
  • 13
  • 29
  • 1
    Hi @Skin! This solution looks great! I get the same result as you both inside variables and in compose actions. I have found my problem too, I had an empty space in the incoming message that has cause all the errors. Thank you very much for helping! – ibda Jul 26 '23 at 08:32
0

I have reproduced in my environment and got expected results as below:

Design:

json(xml(triggerBody()))

enter image description here

Then used outputs('Compose')['SOAP-ENV:Envelope']['SOAP-ENV:Body']['tns:Order'] :

enter image description here

Output:

enter image description here

CodeView:

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Compose": {
                "inputs": "@json(xml(triggerBody()))",
                "runAfter": {},
                "type": "Compose"
            },
            "Compose_2": {
                "inputs": "@outputs('Compose')['SOAP-ENV:Envelope']['SOAP-ENV:Body']['tns:Order']",
                "runAfter": {
                    "Compose": [
                        "Succeeded"
                    ]
                },
                "type": "Compose"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {},
        "triggers": {
            "manual": {
                "inputs": {
                    "schema": {}
                },
                "kind": "Http",
                "type": "Request"
            }
        }
    },
    "parameters": {}
}

Edit:

If you want output in xml:

xml(outputs('Compose_2'))

enter image description here

Output:

enter image description here

Codeview:

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Compose": {
                "inputs": "@json(xml(triggerBody()))",
                "runAfter": {},
                "type": "Compose"
            },
            "Compose_2": {
                "inputs": "@outputs('Compose')['SOAP-ENV:Envelope']['SOAP-ENV:Body']",
                "runAfter": {
                    "Compose": [
                        "Succeeded"
                    ]
                },
                "type": "Compose"
            },
            "Compose_3": {
                "inputs": "@xml(outputs('Compose_2'))",
                "runAfter": {
                    "Compose_2": [
                        "Succeeded"
                    ]
                },
                "type": "Compose"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {},
        "triggers": {
            "manual": {
                "inputs": {
                    "schema": {}
                },
                "kind": "Http",
                "type": "Request"
            }
        }
    },
    "parameters": {}
}
RithwikBojja
  • 5,069
  • 2
  • 3
  • 7
  • Thanks @RithwikBojja! but this will return the data as list of items, I need to keep it as xml – ibda Jul 25 '23 at 10:37
  • @ibda, See at end, I have changed it back to xml using ```xml(outputs('Compose_2'))``` – RithwikBojja Jul 25 '23 at 10:38
  • @ibda check in Edit heading in answer – RithwikBojja Jul 25 '23 at 10:45
  • Hi @RithwikBojja ! I am sorry to not accept the answer but I was getting different erros with this answer. first in compose1: "Unable to process template language expressions in action 'Compose_Rath1' inputs at line '0' and column '0': 'The template language function 'json' parameter is not valid. The provided XML value cannot be parsed: 'Unexpected XML declaration. The XML declaration must be the first node in the document, and no whitespace characters are allowed to appear before it. Line 2, position 3.'. Please see https://aka.ms/logicexpressions#parse for usage details.'. " – ibda Jul 26 '23 at 08:06
  • I have also tried to remove the first line in the xml input, i.e.: and when I do compose1 works but compose3 fail with this error: Unable to process template language expressions in action 'Compose_Rath3' inputs at line '0' and column '0': 'The template language function 'xml' parameter is not valid. The provided value cannot be converted to XML: 'JSON root object has property '@xmlns:xsi' that will be converted to an attribute. A root object cannot have any attribute properties. Consider specifying a DeserializeRootElementName. Path 'outputs.@xmlns:xsi' – ibda Jul 26 '23 at 08:09
  • You shouldnt remove any headers, and I have taken your input as mine and got results , you can clearly see in screen shots too. – RithwikBojja Jul 26 '23 at 08:13