How to convert Word to Word XML in C#, VB.NET

Simple introduction about Word XML

Word XML is a special XML format, which makes Word be able to manipulate the Word documents stored in XML format. It can be divided into two types: WordML(supported by Word 2003) and WordXML(supported by Word 2007). If external applications support Word XML and the generated data follow the Word XML structure, then the data can be processed by Word. In this way, Word XML has become the bridge between Word and other external applications, any XML- formatted document based on Word XML structure can be opened, edited and saved in Word.

Using C#/VB.NET to convert Word to Word XML via Spire.Doc

Spire.Doc enables users to convert word document to Word XML format easily by using the doc.SaveToFile() method. Now, please follow the detail steps below:

Note: Before start, please download Spire.Doc and install it correctly, then add Spire.Doc.dll file from Bin folder as the reference of your project.

This is the screenshot of the original word document:

How to convert Word to Word XML in C#, VB.NET

Step 1: Create a new document instance.

Document doc = new Document();

Step 2: Load the sample word document from file.

doc.LoadFromFile("Spire.Doc for .NET.docx");

Step 3: Save the word document as Word XML format.

For word 2003:
doc.SaveToFile("DocxToWordML.xml", FileFormat.WordML);

For word 2007:
doc.SaveToFile("DocxToWordXML.xml", FileFormat.WordXml);

Effective screenshot:

How to convert Word to Word XML in C#, VB.NET

Full codes:

[C#]
using Spire.Doc;

namespace Convert_Word_to_Word_XML
{
    class Program
    {
        static void Main(string[] args)
        {
            Document doc = new Document();
            doc.LoadFromFile("Spire.Doc for .NET.docx");
            doc.SaveToFile("DocxToWordML.xml", FileFormat.WordML);
            //doc.SaveToFile("DocxToWordXML.xml", FileFormat.WordXml);
        }
    }
}
[VB.NET]
Imports Spire.Doc
Namespace Convert_Word_to_Word_XML
	Class Program
		Private Shared Sub Main(args As String())
			Dim doc As New Document()
			doc.LoadFromFile("Spire.Doc for .NET.docx")
			doc.SaveToFile("DocxToWordML.xml", FileFormat.WordML)
			'doc.SaveToFile("DocxToWordXML.xml", FileFormat.WordXml);
		End Sub
	End Class
End Namespace