Free Support Forum - aspose.com

Insert document.xml content in a Word Document

Hello,

I would like to know if it is possible to insert the content of a document.xml file (result of an unzip of a Word docx file) in a Aspose Document ?

Scenario :
Create a Word OpenXML document, and write some text (for example : ‘This is an example’).
Save the document, unzip and extract the file ‘document.xml’ which is the ‘content’ of the document.
the content will be :
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<w:body><w:p w:rsidR=“00F13749” w:rsidRDefault=“00195CF4”><w:r><w:t>This is my example</w:t></w:r></w:p><w:sectPr w:rsidR=“00F13749”><w:pgSz w:w=“11906” w:h=“16838”/><w:pgMar w:top=“1417” w:right=“1417” w:bottom=“1417” w:left=“1417” w:header=“708” w:footer=“708” w:gutter=“0”/><w:cols w:space=“708”/><w:docGrid w:linePitch=“360”/></w:sectPr></w:body></w:document>


Create with Aspose a new document programmatically (Document documentCreatedWithAspose = new Document())

Can I add the content of the document.xml file in my ‘documentCreatedWithAspose’ programmatically so that the document text will be : This is my example?


I try to use the VisitorDocument but I need to get a .doc file… and
I try to avoid to create a .doc file (and get it from FileSystem).


I try to create a new document with a stream which contains the XML content, but the FileFormatInfo.getLoadFormat() returns a LoadFormat.UNKNOWN

I see there is a LoadFormat.FLAT_OPC which can be usefull for my need, but I don’t know how to use it ?


Regards.

Hi Roseline,


Thanks for your query.

Aspose.Words provides exhaustive support for different XML-based formats for word processing documents e.g. OOXML, Flat OPC and also Word 2003 XML. You can load these formats directly by using Aspose.Words’ Document constructor but can not load the document.xml with Document.

Please note that Aspose.Words is quite different from the Microsoft Word’s Object Model in that it represents the document as a tree of objects more like an XML DOM tree. If you worked with any XML DOM library you will find it is easy to understand and work with Aspose.Words. When you load a Word document into Aspose.Words, it builds its DOM and all document elements and formatting are simply loaded into memory. Please read the following articles for more information on DOM:
http://www.aspose.com/docs/display/wordsnet/Object+Model+Overview
http://www.aspose.com/docs/display/wordsnet/Composition+Diagrams

Hope this answers your query. Please let us know if you have any more queries.