Hi,
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/"> <s:Body> <SMSGateWayResponse xmlns="http://xxxx"> <SMSGateWayResult xmlns:a="http://xxxx" xmlns:i="xxxxx"> <a:ErrCode>OK</a:ErrCode> <a:ErrMsg>OK</a:ErrMsg> </SMSGateWayResult> </SMSGateWayResponse> </s:Body> </s:Envelope> ''' 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
commentManager.create( issue, user, "response: $res", false)
But console returns me error No such property: SMSGateWayResponse for class: groovy.util.slurpersupport.GPathResult.
This is not working, too.
Please help!
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.