Perchishka
8 years agoOccasional Contributor
How to trim white space after XMLParser
Hello!
I have an xml.file
and I need to generate random UUID and Date for every request.
So I decided to write a groovy script:
TimeZone.setDefault(TimeZone.getTimeZone("Europe/Moscow")); def now = new Date((System.currentTimeMillis() - 3600000L)) String s = now.format("yyyy-MM-dd'T'HH:mm:ss.SSS")+"+03:00" log.info(s) context.testCase.setPropertyValue('currentDateForXml', s) stringXML = '''<SmsSubscriptionsTarifficationNotifies xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="***.xsd"> <TarifficationNotify> <TransactionId>971f513e-ff56-4b9b-9910-cd1acec12fab</TransactionId> <SubscriptionId>f6b3f278-d6fd-48a7-b8c4-5e5570a2b0a0</SubscriptionId> <ContentId>de1b0145-f4ae-48b4-a216-f5d8e302760</ContentId> <MSISDN>79855575412</MSISDN> <AttemptDate>2017-06-16T00:10:13.9+03:00</AttemptDate> <Result>false</Result> <FaultCode>102</FaultCode> </TarifficationNotify> <TarifficationNotify> .... the same story </TarifficationNotify> </SmsSubscriptionsTarifficationNotifies>''' def parsedXml = new XmlParser().parseText(stringXML) log.info(parsedXml ) def dt = parsedXml.'**'.TransactionId log.info(dt) dt.each{it.value = randomUUID() as String} def dd = parsedXml.'**'.AttemptDate log.info(dd) dd.each{it.value = s} def sw = new StringWriter() new XmlNodePrinter(new PrintWriter(sw)).print(parsedXml) def newXml = sw.toString() context.testCase.setPropertyValue('newXml', newXml)
and i need to set new xml in property to use it for SOAP request
But added to the properties xml looks like:
<SmsSubscriptionsTarifficationNotifies xmlns="https://moipodpiski.ssl.mts.ru/xsd/SmsSubscriptionsTarifficationNotifies.xsd"> <TarifficationNotify> <TransactionId> d897fad0-3cd4-4c2a-a317-f69c976906ae </TransactionId> <SubscriptionId> 75cc04d4-b84a-4dbf-a881-d6fe39552083 </SubscriptionId> <ContentId> d2e1edd5-4e3c-4a80-a189-0f52e1b756ec </ContentId> <MSISDN> 79855575412 </MSISDN> <AttemptDate> 2017-06-16T00:10:13.9+03:00 </AttemptDate> <Result> false </Result> <FaultCode> 102 </FaultCode> </TarifficationNotify> </SmsSubscriptionsTarifficationNotifies>
a lot of white spaces and as a result I have an invalid request
Could you help me please
How to remove spaces inside tags?