Forum Discussion

Mis3's avatar
Mis3
Frequent Contributor
3 years ago
Solved

if multiple attributes in a XML response, how to separate them in log.info?

I am working on yet another Groovy script to send the same testStep to an external source with different properties (read from a CSV file). I like to improve on the log report.    Below are a sampl...
  • nmrao's avatar
    nmrao
    3 years ago

    Mis3 

     

    I believe that we have to first understand  how things work rather than saying "did not work".

     

    Each solution would depend on the data.

     

    You can try this excerpt

    Note, this is not full script

     

     

     

    def xml = new XmlSlurper().parseText(xmlResponse)
    def getData = { childElement, parentElement = null ->
    	if (parentElement) {
    		xml.'**'.findAll {it.name() == parentElement}."$childElement"*.text()
    	} else {
    		xml.'**'.findAll {it.name() == childElement}*.text()
    	}
    }
    def list = ["Seq=${i}", data[0], "Status=${getData('errorCode')}", getData('fullName'), getData('networkId'), getData('code', 'service'), getData('value', 'avp')]
    log.info list.flatten().join(' ')

     

     

     

    log.info => this statement any ways  shows the data time. You don't have to explicit add the date time again.

     

    EDIT:

    Haved edited the script based on your latest reply. Please the script one more time and try.