0

I have an XML as below:

String xml = """  
    <?xml version="1.0" encoding="UTF-8"?>
    <soapenv:Envelope>
        <soapenv:Body>
            <processAsyncRequest></processAsyncRequest>
        </soapenv:Body>
    </soapenv:Envelope>  
"""  

Using Groovy, i want to find the first node name inside "Body" using XPath (//:Body/[1]/name())

Output Should be : processAsyncRequest 

I am parsing the xml using XmlSlurper. But couldnt figure out the next steps to get node name using XPath

def rootNode = new XmlSlurper().parseText(xml)  

Is there any simple way to achieve this? Note : the structure of my xml changes every time. So i want to use Relative Path.

1 Answer 1

1

but that's not XPath. it's GPath

String xml = """<?xml version="1.0" encoding="UTF-8"?>
    <soapenv:Envelope xmlns:soapenv='...'>
        <soapenv:Body>
            <processAsyncRequest></processAsyncRequest>
        </soapenv:Body>
    </soapenv:Envelope>  
"""  
def rootNode = new XmlSlurper().parseText(xml)

println rootNode.Body.'*'[0].name()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.