Forum Discussion

Dizzo's avatar
Dizzo
Occasional Contributor
8 years ago

Need help with XmlSlurper

Hello guys,   I hope you can help me with parsing xml report by Groovy XmlSlurper. I need to get maximum date of issuance of ID card. Can anybody help, im noob in this, it's so hard to me.     ...
  • PaulMS's avatar
    PaulMS
    8 years ago

    XmlHolder was easier because I wasn't sure about sorting nodes in XmlSlurper.

     

    To filter the nodes and sort the dates in an array

     

    def xml = new XmlSlurper().parseText(response)
    docs = xml.Result.Root.IdentificationDocuments.Document.findAll { it.Name.@value == 'ID card' && it.DateOfIssuance.@value != '-' }
    dates = []
    docs.each {dates.add it.DateOfIssuance.@value.text()}
    log.info dates.sort { Date.parse('dd.MM.yyyy', it ) }.reverse()[0]