'No such property for class' using XmlSlurper


I have an xml response from web service and need to parse it to set some details of this response (values of ErrCode and ErrMsg elements) to the comments of the issue. All this must be done from the Custom-script postfunction. This is what i've done:

import groovy.xml.*
import groovy.util.XmlSlurper
def xml = '''
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
	<SMSGateWayResponse xmlns="http://xxxx">
		<SMSGateWayResult xmlns:a="http://xxxx" xmlns:i="xxxxx">
def xmlresult = new XmlSlurper().parseText(xml)
//want to do something like this
def res = xmlresult.Body.SMSGateWayResponse.SMSGateWayResult.ErrMsg.text()

and this res result is added to the comment

        "response: $res",

But console returns me error No such property: SMSGateWayResponse for class: groovy.util.slurpersupport.GPathResult.

This is not working, too. 

Please help! 

1 answer

Do you need to use SOAP? It's not very user friendly. If you're using some system for SMS sending I'm sure it has a REST API.

I don't see where you're actually executing the request to the remote system, or is this just test code?

For XML with namespaces you have to do some more stuff - see http://stackoverflow.com/questions/8669766/namespace-handling-in-groovys-xmlslurper.

Hi Jamie, 

Thanks, I've found this a day ago and now the script works. 

This xml is the response of our web service, I've used it as a test case to see how it can be parsed.

def xmlresult = new XmlSlurper().parseText(xml)
assert xmlresult instanceof groovy.util.slurpersupport.GPathResult
def res = xmlresult.Body
//return res in Script console or adding a comment in workflow post function
Result.Body returns me OKOK (ErrCode and ErrMsg). Dont know how to separate them. 
 If I try to go deeply into the xml tree ( xmlresult.Body.SMSGateWayResponse ) the system returns that there is not such property. 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 29, 2018 in Marketplace Apps

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,711 views 3 11
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you