I’m having trouble working with the REST plugin in grails. Specifically I am trying to convert xml from a get request into a Map in a controller.
The data source I am trying to get data from returns XML that looks like this (this is shortened for simplicity):
<process id="345">
<correctedBy>Joanne W.</correctedBy>
<editBy>Joanne W.</editBy>
<editDate>2009-12-23 00:00:00.0 EST</editDate>
<produceBy>Stephen</produceBy>
<produceDate>2010-01-14 00:00:00.0 EST</produceDate>
</process>
In my controller I have code to make the get request to this service
def getRest = {
def wfRequest
withHttp(uri: "http://myurl:8080") {
wfRequest = get(path : '/application/controller/' + params.id,
requestContentType: XML) { resp, xml ->
render xml
}
}
}
Ok so far, this will return the data from the xml, but all the tags are gone:
Joanne W.Joanne W.2009-12-23 00:00:00.0 ESTStephen2010-01-14 00:00:00.0 EST
Can anyone point me in the right direction on how to access the XML that is returned from this request? I’d like to step through each kay value pair in the “process” node of the xml and populate a map that would look like
[correctedBy: Joanne W., editBy: Joanne W., editDate: 2009-12-23 00:00:00.0 EST, produceBy: Stephen, produceDate: 2010-01-14 00:00:00.0 EST]
I’m finding the rest plugin documentation a little confusing, any help would be GREATLY appreciated.
Thanks!
Donald
It makes sense that when you say render xml it doesn’t show the tags. At this point, XML is an XmlSlurper object, so it’s just calling the toString().
See this for more information.
So since you have an XmlSlurper, you just need to use it.