none
How to obtain child nodes only using Xpath in Logic Apps RRS feed

  • Question

  • Hi,

    I am trying to obtain the child nodes of <Task> in the following XML message:

    <soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:opt='http://www.test.com/OptionalParameters' xmlns:cts='http://www.test.com'>
        <soapenv:Header>
            <opt:OptionalParameters/>
        </soapenv:Header>
        <soapenv:Body>
            <Process>
                <Task>
                    <ID>M2M0YZ</ID>
                    <DueDate>2019-01-10T09:22:36</DueDate>
                    <Customer>Test</Customer>
                    <Open>2019-01-10T08:22:36</Open>
                <Task>

    <ProcessTask>

    I am currently using the following Xpath syntax, stored as a string variable: 

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

    This returns the correct values, however, I would like the returned collection of nodes to exclude the <Task> tag from the top and bottom.  Is there a way to simply just return the child nodes without the parent node?

    Thanks.


    Thursday, November 14, 2019 2:51 AM

All replies

  • The simplest way is to read each child node individually as shown below:

    xpath(xml(outputs('Compose')),'//*[local-name()="ID"]')
    
    xpath(xml(outputs('Compose')),'//*[local-name()="DueDate"]')
    
    xpath(xml(outputs('Compose')),'//*[local-name()="Customer"]')
    
    xpath(xml(outputs('Compose')),'//*[local-name()="Open"]')

    Alternatively convert your XML to Json and read the Task Node as shown below:

    json(xml(triggerBody()))['soapenv:Envelope']['soapenv:Body']['Process']['Task']


    Thursday, November 14, 2019 1:53 PM
    Moderator
  • Hi,

    Thanks for the reply.  I've used your code to convert the XML to JSON which works just fine.  I now need to convert it back to XML once I've added the extra data. What is the best way to do this please?  

    Sunday, November 17, 2019 9:58 PM