Search code examples
xmlxpathsoapazure-logic-apps

xpath expression not working in Logic Apps


I have the following XML response from a SOAP call

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soap:Body>
        <GetContractStatusesResponse xmlns="http://www.proactis.com/xml/xml-ns/">
            <GetContractStatusesResult>
                <Message>Successful</Message>
                <Code>1</Code>
                <InterfaceLanguage>de</InterfaceLanguage>
                <GetContractStatusesData xmlns="http://schemas.proactis.com/p4/contractmanagement/2013/02">
                    <ContractStatus code="DRFT" typeId="3581">Draft</ContractStatus>
                    <ContractStatus code="BAPR" typeId="3582">Being Approved</ContractStatus>
                    <ContractStatus code="RJCT" typeId="3583">Rejected</ContractStatus>
                    <ContractStatus code="CNCL" typeId="3584">Cancelled</ContractStatus>
                    <ContractStatus code="APPR" typeId="3585">Approved</ContractStatus>
                    <ContractStatus code="ACPE" typeId="3586">Activation Pending</ContractStatus>
                    <ContractStatus code="ACTV" typeId="3587">Active</ContractStatus>
                    <ContractStatus code="SUSP" typeId="3588">Suspended</ContractStatus>
                    <ContractStatus code="COMP" typeId="3589">Completed</ContractStatus>
                    <ContractStatus code="NOV" typeId="3783">Novated</ContractStatus>
                    <ContractStatus code="DEF" typeId="3853">In Defects Period</ContractStatus>
                </GetContractStatusesData>
            </GetContractStatusesResult>
        </GetContractStatusesResponse>
    </soap:Body>
</soap:Envelope>

I am trying to create an xpath reference to retrieve an array of GetContractStatusesData so that i can then loop through each ContractStatus to use the value and also the associated code as well

I have tried various online xpath generators but they dont seem to work properly when imported into Logic Apps, and even to try something more simpler like getting the message value.

These are the ones i have tried by setting a logic app variable

xpath(xml(variables('Payload')), '//ContractStatus[1]/@code')
xpath(xml(variables('Payload')), '//ContractStatus[1]/text()[1]')

The result I typically get back is []


Solution

  • I have contacted Microsoft about this and the solution was to use the Compose Action on the XML to JSON using the following, that way JSON is much easer to work with.

    json(xml(<XML content>))