I have an XML request in the form of a file, that I want to add to a taurus yaml file. The yaml file requires a single line string.
I have it working with a json file by doing this;
strMessage=getFileContents("request.json");
//Use a jsonslurper to process the message
def jsonSlurper = new groovy.json.JsonSlurper()
def mapMessage = jsonSlurper.parseText(strMessage)
def jsonMessage= groovy.json.JsonOutput.toJson(mapMessage)
request = jsonMessage
So I'm trying the same process with the xml equivalents;
strMessage=getFileContents("request.xml")
//Use an xmlslurper to process the message
def xmlSlurper = new groovy.util.XmlSlurper()
def mapMessage = xmlSlurper.parseText(strMessage)
def xmlMessage = groovy.util.XmlUtil.serialize(mapMessage)
request = xmlMessage
Unfortunately while the json output comes out all on one line, the xml version comes out similar to the file with lots of line breaks.
The reason why I'm using slurpers is to reformat the files as I don't have control over the source files. It did occur to me that I could just ingest the file and remove the line breaks but the request in the yaml file would have huge amounts of whitespace. And obviously I can't remove line breaks and whitespace because some whitespace is valid.
Up to the 'mapMessage' it is working as expected, it's just the last bit to convert the map into a single XML string that has me beat. what command will output a Groovy map object to a single line XML?