We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

DOCX to XML Conversion


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


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


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




// 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,


I am able to convert xml to Docx.