serafim
serafim

Reputation: 75

parsing XML gives me a list of slurpersupport attributes but I want a list of texts

I fetch an xml file from the internet using a URL

def url = "http://www.kth.se/api/kopps/v1/course/DD1390/round/2014:2/1".toURL()
InputStream inp = url.openStream()
def kursomgXML = new XmlSlurper().parse(inp).declareNamespace(xml:'http://www.w3.org/XML/1998/namespace')

I used the following :

courseRound.courseResponsibleList.courseResponsible.@primaryEmail.list()

which seemed to work fine but when using the result in a method call I get an error saying that no signature of the method is applicable on a value of type groovy.util.slurpersupport.Attribute

How do I get a list of strings instead of a list of slurpersupport attributes?

Upvotes: 1

Views: 191

Answers (1)

cfrick
cfrick

Reputation: 37008

you can call .text() on the attribute to get a string. or e.g. spread (*.) it over the list

courseRound.courseResponsibleList.courseResponsible.list().'@primaryEmail'*.text()

Upvotes: 2

Related Questions