Objective: My code will take a xml value and print it on a .docx file with proper xml structure.
Please guide me.
- Code: Select all
package org.docx4j.samples;
import groovy.xml.*
import org.docx4j.openpackaging.packages.WordprocessingMLPackage
import org.docx4j.XmlUtils;
def xmlUtils = new com.eviware.soapui.support.xml.XmlUtils()
def groovy=new com.eviware.soapui.support.GroovyUtils(context)
def project=context.testCase.testSuite.project
def request=project.getTestSuiteAt(0).getTestCaseAt(0).getTestStepAt(4).getProperty("Request").getValue()
log.info request
def response=project.getTestSuiteAt(0).getTestCaseAt(0).getTestStepAt(4).getProperty("Response").getValue()
log.info response
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
wordMLPackage.getMainDocumentPart().addParagraphOfText(XmlUtil.serialize(request).toString());
wordMLPackage.save(new java.io.File("C:\\HelloWord1.docx"));
[*]At present Output is coming below:[/*]
- Code: Select all
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:hp="HP.SOAQ.SampleApp"> <soapenv:Header/> <soapenv:Body> <hp:GetFlights> <!--Optional:--> <hp:DepartureCity>Denver</hp:DepartureCity> <!--Optional:--> <hp:ArrivalCity>London</hp:ArrivalCity> </hp:GetFlights> </soapenv:Body> </soapenv:Envelope>
[*]OUTPUT SHOULD COME LIKE BELOW:[/*]
- Code: Select all
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:hp="HP.SOAQ.SampleApp">
<soapenv:Header/>
<soapenv:Body>
<hp:GetFlights>
<!--Optional:-->
<hp:DepartureCity>Denver</hp:DepartureCity>
<!--Optional:-->
<hp:ArrivalCity>London</hp:ArrivalCity>
</hp:GetFlights>
</soapenv:Body>
</soapenv:Envelope>