Before I place my query here, let me put in brief what I have done so far.
I have iterated over the content controls (W:SDT) and converted the contents in HTML and successfully saved into database. For this process, I have used openxml4j and xpath to iterate over each node and generate appropriate html.
Now I have been asked to re-create a docx out of the html which I have saved in database. In this regard, I have introduced one more column in the table(database) so that I can insert the openxml which would help me in generating the docx.
Here is the issue i find difficult to re-create the docx from the openxml.
My sample openxml ( toString) is as follows:
- Code: Select all
<w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" w:rsidP="0086466A" w:rsidR="0086466A" w:rsidRDefault="0086466A">
<w:r>
<w:t xml:space="preserve">What is the area of a circle whose radius is 5 </w:t>
</w:r>
<w:proofErr w:type="gramStart"/>
<w:r>
<w:t>cm ?</w:t>
</w:r>
<w:proofErr w:type="gramEnd"/>
<w:r>
<w:t xml:space="preserve"> </w:t>
</w:r>
<m:oMath xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math">
<m:r>
<w:rPr>
<w:rFonts w:ascii="Cambria Math" w:hAnsi="Cambria Math"/>
</w:rPr>
<m:t>A=π</m:t>
</m:r>
<m:sSup>
<m:sSupPr>
<m:ctrlPr>
<w:rPr>
<w:rFonts w:ascii="Cambria Math" w:hAnsi="Cambria Math"/>
</w:rPr>
</m:ctrlPr>
</m:sSupPr>
<m:e>
<m:r>
<w:rPr>
<w:rFonts w:ascii="Cambria Math" w:hAnsi="Cambria Math"/>
</w:rPr>
<m:t>r</m:t>
</m:r>
</m:e>
<m:sup>
<m:r>
<w:rPr>
<w:rFonts w:ascii="Cambria Math" w:hAnsi="Cambria Math"/>
</w:rPr>
<m:t>2</m:t>
</m:r>
</m:sup>
</m:sSup>
</m:oMath>
</w:p>
Java code to generate the docx :
- Code: Select all
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
wordMLPackage.getMainDocumentPart().addObject(XmlUtils.unmarshalString(openxmlString));//Paragraph node toString().
wordMLPackage.save(new java.io.File("output filepath"));
It is generating the docx but pi becomes unrecognised and replaced by ?. I hope you' have got what I meant to say.
How do I solve this?
Pls help