DOCX to XML Conversion

Hi,

I am trying to convert DOCX to XML using Aspose word.


Code:

com.aspose.words.LoadOptions loadOptions = new LoadOptions();

loadOptions.setLoadFormat(LoadFormat.WORD_ML);

Document asposeDoc = new Document(new ByteArrayInputStream(wordML.getBytes()), loadOptions);

ByteArrayOutputStream outStream = new ByteArrayOutputStream();

asposeDoc.save(outStream, DOCX_SAVEFORMAT);

// data bytes and wrap into an input stream.

ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray());

byte[] bytes = IOUtils.toByteArray(inStream);

// close all streams

outStream.flush();

outStream.close();

inStream.close();

// return



return bytes;

When save the bytes as docx in my local. Its not opening its throwing file corrupted error and when I try to open the docx in word pad its showing xml content

Please advice how to convert word XML To Docx
Hi Muthu,

Thanks for your inquiry. Please upgrade to the latest version of Aspose.Words and try using the following code:
Document doc = new Document(xml file path);

/* Perform any document processing tasks here */

// Save the modified document into out stream
ByteArrayOutputStream baos = new ByteArrayOutputStream();
doc.save(baos, SaveFormat.DOCX);

// You can then get the document back into the InputStream as follows
InputStream inputStream = new ByteArrayInputStream(baos.toByteArray());

Hope, this helps.

Best regards,

Thanks.

I am able to convert xml to Docx.