none
Logic App xpath(xml(body()),'') returns [{\"$content-type\":\"application/xml;charset=utf-8\",\"$content\":\ RRS feed

  • Question

  • I call a Web Service using a HTTP action which returns a SOAP message (See below) with the Content-Type set to text/xml.

    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
     <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <Address xmlns="http://www.qas.com/web-2009-08">
       <QAAddress>
        <AddressLine LineContent="Address">
         <Label>Organisation</Label>
         <Line/>
        </AddressLine>
        <AddressLine LineContent="Address">
         <Label>PO Box (Number)</Label>
         <Line/>
        </AddressLine>
        <AddressLine LineContent="Address">
         <Label>Sub-building name</Label>
         <Line/>
        </AddressLine>
        <AddressLine LineContent="Address">
         <Label>Building name</Label>
         <Line/>
        </AddressLine>
        <AddressLine LineContent="Address">
         <Label>Building number</Label>
         <Line>99</Line>
        </AddressLine>
        <AddressLine LineContent="Address">
         <Label>Sub-building number</Label>
         <Line/>
        </AddressLine>
        <AddressLine LineContent="Address">
         <Label>Dependent thoroughfare</Label>
         <Line/>
        </AddressLine>
        <AddressLine LineContent="Address">
         <Label>Thoroughfare</Label>
         <Line>Long Drive</Line>
        </AddressLine>
        <AddressLine LineContent="Address">
         <Label>Double dependent locality</Label>
         <Line/>
        </AddressLine>
        <AddressLine LineContent="Address">
         <Label>Dependent locality</Label>
         <Line/>
        </AddressLine>
        <AddressLine LineContent="Address">
         <Label>Town</Label>
         <Line>London</Line>
        </AddressLine>
        <AddressLine LineContent="Address">
         <Label>County</Label>
         <Line>Hertfordshire</Line>
        </AddressLine>
        <AddressLine LineContent="Address">
         <Label>Postcode</Label>
         <Line>ZZ3 5ZZ</Line>
        </AddressLine>
       </QAAddress>
      </Address>
     </s:Body>
    </s:Envelope>

    I then want to strip off the SOAP Envelope and Body to get just the Address element and below so I use the following expression in my next Action...

    xpath(xml(body('Call_QA_Get_Address')),'/*[local-name()="Envelope" and namespace-uri()="http://schemas.xmlsoap.org/soap/envelope/"]/*[local-name()="Body" and namespace-uri()="http://schemas.xmlsoap.org/soap/envelope/"]/*[local-name()="Address" and namespace-uri()="http://www.qas.com/web-2009-08"]')

    But what I get output is the following...

    [{\"$content-type\":\"application/xml;charset=utf-8\",\"$content\":\"PEFkZHJlc3MgeG1sbnM9Imh0dHA6Ly93d3cucWFzLmNvbS93ZWItMjAwOS0wOC.........."}]

    Has anyone any idea what might be the issue here and how to correct it, thanks?

    Thursday, October 17, 2019 3:07 PM

All replies

  • Hello Stewart Joyce,

    Try something as below to get your <Address> node:

    xml(decodeBase64(xpath(xml(outputs('Call_QA_Get_Address')),'/*[local-name()="Envelope" and namespace-uri()="http://schemas.xmlsoap.org/soap/envelope/"]/*[local-name()="Body"]/*[local-name()="Address" and namespace-uri()="http://www.qas.com/web-2009-08"]')[0]?['$content']))
    

    Friday, October 18, 2019 6:14 AM
    Moderator
  • Ketan

    Thanks. I tried this but got this error when I tried to run the Logic App...

    InvalidTemplate. Unable to process template language expressions in action 'Execute_Address_To_ESBAddressEntry_Map' inputs at line '1' and column '1413': 'The template language function 'xml' parameter is not valid. The provided value cannot be converted to XML: 'JSON root object has multiple properties. The root object must have a single property in order to create a valid XML document. Consider specifying a DeserializeRootElementName. Path 'outputs.headers'.'. Please see https://aka.ms/logicexpressions#xml for usage details.'.

    Friday, October 18, 2019 7:43 AM
  • Hello Stewart Joyce,

    Here is my complete Codeview, I have used Compose Action to create an XML as your:

    {
        "definition": {
            "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
            "actions": {
                "Compose": {
                    "inputs": "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <s:Body xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\n  <Address xmlns=\"http://www.qas.com/web-2009-08\">\n   <QAAddress>\n    <AddressLine LineContent=\"Address\">\n     <Label>Organisation</Label>\n     <Line/>\n    </AddressLine>\n    <AddressLine LineContent=\"Address\">\n     <Label>PO Box (Number)</Label>\n     <Line/>\n    </AddressLine>\n    <AddressLine LineContent=\"Address\">\n     <Label>Sub-building name</Label>\n     <Line/>\n    </AddressLine>\n    <AddressLine LineContent=\"Address\">\n     <Label>Building name</Label>\n     <Line/>\n    </AddressLine>\n    <AddressLine LineContent=\"Address\">\n     <Label>Building number</Label>\n     <Line>99</Line>\n    </AddressLine>\n    <AddressLine LineContent=\"Address\">\n     <Label>Sub-building number</Label>\n     <Line/>\n    </AddressLine>\n    <AddressLine LineContent=\"Address\">\n     <Label>Dependent thoroughfare</Label>\n     <Line/>\n    </AddressLine>\n    <AddressLine LineContent=\"Address\">\n     <Label>Thoroughfare</Label>\n     <Line>Long Drive</Line>\n    </AddressLine>\n    <AddressLine LineContent=\"Address\">\n     <Label>Double dependent locality</Label>\n     <Line/>\n    </AddressLine>\n    <AddressLine LineContent=\"Address\">\n     <Label>Dependent locality</Label>\n     <Line/>\n    </AddressLine>\n    <AddressLine LineContent=\"Address\">\n     <Label>Town</Label>\n     <Line>London</Line>\n    </AddressLine>\n    <AddressLine LineContent=\"Address\">\n     <Label>County</Label>\n     <Line>Hertfordshire</Line>\n    </AddressLine>\n    <AddressLine LineContent=\"Address\">\n     <Label>Postcode</Label>\n     <Line>ZZ3 5ZZ</Line>\n    </AddressLine>\n   </QAAddress>\n  </Address>\n </s:Body>\n</s:Envelope>",
                    "runAfter": {},
                    "type": "compose"
                },
                "Response": {
                    "inputs": {
                        "body": "@xml(decodeBase64(xpath(xml(outputs('Compose')),'/*[local-name()=\"Envelope\" and namespace-uri()=\"http://schemas.xmlsoap.org/soap/envelope/\"]/*[local-name()=\"Body\"]/*[local-name()=\"Address\" and namespace-uri()=\"http://www.qas.com/web-2009-08\"]')[0]?['$content']))",
                        "statusCode": 200
                    },
                    "kind": "http",
                    "operationOptions": "Asynchronous",
                    "runAfter": {
                        "Compose": [
                            "Succeeded"
                        ]
                    },
                    "type": "Response"
                }
            },
            "contentVersion": "1.0.0.0",
            "outputs": {},
            "parameters": {},
            "triggers": {
                "manual": {
                    "inputs": {
                        "schema": {}
                    },
                    "kind": "Http",
                    "type": "Request"
                }
            }
        }
    }

    Friday, October 18, 2019 8:21 AM
    Moderator
  • Hello Stewart Joyce,

    Any Update on this thread?

    Monday, October 21, 2019 4:43 AM
    Moderator