How to edit or process a fragment of Open XML Document (i.e. docx)?

I have a fragment of Open XML document from a Word 2007 DOCX document like the following:

<w:p w:rsidR="00000000" w:rsidRDefault="00A50201">
	<w:pPr>
		<w:keepNext />
		<w:keepLines />
		<w:tabs>
			<w:tab w:val="left" w:pos="2160" />
		</w:tabs>
		<w:suppressAutoHyphens />
		<w:adjustRightInd />
		<w:spacing w:line="300" w:lineRule="auto" />
		<w:rPr>
			<w:lang w:val="en-GB" />
		</w:rPr>
	</w:pPr>
	<w:r>
		<w:rPr>
			<w:lang w:val="en-GB" />
		</w:rPr>
		<w:t>Name:</w:t>
	</w:r>
	<w:r>
		<w:rPr>
			<w:lang w:val="en-GB" />
		</w:rPr>
		<w:tab />
	</w:r>
	<w:r>
		<w:t>|EE_NAME|</w:t>
	</w:r>
</w:p>

This fragment has been loaded into memory as a string from the database. But I can’t figure out a correct solution to edit or process it for having the following issues:

  1. Aspose.Words doesn’t provide any of API that takes a string parameter to process the WordML fragment.
  2. I have tried to use MemoryStream to load that fragment WordML string, but getting the “Unsupported FileFormat Exception” with “Unknown file format.” error message.
  3. I have also tried to create a separate xml file with the above WordML fragment, but still gets the same UnsupportedFileFormatException when trying to create the document using the file.

I also tried the other fragment of WordML text as follow, but still got the same problems:

<w:p w:rsidR="00000000" w:rsidRDefault="00A50201">
	<w:pPr>
		<w:keepNext />
		<w:keepLines/>
		<w:widowControl />
		<w:suppressAutoHyphens/>
		<w:rPr>
			<w:lang w:val="en-GB"/>
		</w:rPr>
	</w:pPr>
	<w:r>
		<w:rPr>
			<w:lang w:val="en-GB" />
		</w:rPr>
		<w:t>
			If you choose to receive a deferred
			pension, y
		</w:t>
	</w:r>
	<w:r>
		<w:rPr>
			<w:lang w:val="en-GB" />
		</w:rPr>
		<w:t>
			ou should be aware of the
			following.
		</w:t>
	</w:r>
</w:p>
<w:p w:rsidR="00000000" w:rsidRDefault="00A50201">
	<w:pPr>
		<w:keepNext />
		<w:keepLines />
		<w:suppressAutoHyphens />
		<w:adjustRightInd />
		<w:rPr>
			<w:lang w:val="en-GB" />
		</w:rPr>
	</w:pPr>
</w:p>

Does anyone have any thoughts of this issue?

Besides the above problem, I am also looking for a solution that can take this WordML fragment to display into a RichText editor (i.e. Html editor or any WYSIWYG editor) that can let user further edit the text and save the change. (similar to copy a portion from a Word DOCX document and paste to another rich text editor to edit). Any ideas for this will be very appreciated!

Hi

Thanks for your request. I am afraid it is impossible to achieve what you are asking for. DOCX (OOXML) documents consist of several parts, which are required to build Document Object Model. Snippet of XML you provided is just a snippet of document.xml part, but there should also be styles, lists, font table and other required parts.
http://en.wikipedia.org/wiki/Open_Packaging_Conventions
So a snippet of xml cannot be considered as a valid document and cannot be opened.
Best regards.

Thanks Alexey for your reply. If this is the case. Then what if I have RTF blocks in memory, something like:

\pard\plain \sl300\slmult1\keep\keepn\nowidctlpar\tx1728\hyphpar0\adjustright \fs22 {\lang2057 \par }\pard \sl300\slmult1\keep\nowidctlpar\tx2160\hyphpar0\adjustright {\lang2057 Name:\tab }{|EE_NAME|}{\lang2057 \par }

This RFT block can be paste to a Word 97 document and save as a individual doc file. So is there any way to use Aspose to convert that RTF block into docx compatible part (or a docx file) that we can use them to further compose into a single docx file?

Thanks!

Hi

Thanks for your request. The same thing applies to RTF. RTF string should be a valid RTF document. But in your case this is just set of RTF tags.
Best regards.