Page 1 of 1

Need help in Docx file creation with Pretty print

PostPosted: Wed Jan 14, 2015 2:53 am
by shuvadip02
I have wrote an groovy script in soapui for .docx file creation by docx4j , its working fine and printing also . But the request XML and response XML are not coming in Pretty print , its coming as a paragraph.
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>

Re: Need help in Docx file creation with Pretty print

PostPosted: Wed Jan 14, 2015 9:15 am
by jason
shuvadip02 wrote:Objective: My code will take a xml value and print it on a .docx file with proper xml structure.


If I'm understanding you correctly, two steps:

1. you need to pretty print your "XML value". How you do this will depend on what sort of object it is (eg DOM document, string) and your programming language/libs.

2. once you have that, then you can use docx4j to make a paragraph for each line (or a single paragraph with a soft return between each line).