Easy Method to Convert Word to XML with C#/VB.NET

XML Introduction

XML(Extensible Markup Language) is one kind of source language which allows users to define own markup language. It can make marked electronic files have structure, mark data and define data type. Also, it offers only one method to describe and exchange structural data which is independent of application.

Although XML can be used to save data, it is much different from database. Database is powerful on data storage and analytics, while XML just displays data. Actually, XML is very simple so that it can be easily used to read and write data in any applications. Also, it becomes the most frequently used language to exchange data.

Convert Word to XML

Sometimes, in order to deliver data information through internet, people may convert Word document to XML. In this post, I will introduce a method to convert Word to XML with C#/VB.NET quickly and easily.

I used Spire.Doc for .NET, a .NET Word component specializing in manipulate Word document in my example. Therefore, I add its dll file as reference in my project.

Detailed Steps Shown as Following:          

I. Load Word document which I want to convert to xml by using document.LoadFromFile() method. Parameter passed to this method is file name string.


            Document document = new Document();
            document.LoadFromFile(@”E:\work\Documents\Blues Introduction.docx”);


            Dim document As New Document()
            document.LoadFromFile(“E:\work\Documents\Blues Introduction.docx”)

II. Convert Word document to XML file by using document.SaveToFile() method. Two parameters are passed to this method, string file name and file format.


            document.SaveToFile(“XML.xml”, FileFormat.Xml);


           document.SaveToFile(“XML.xml”, FileFormat.Xml)

III. Launch this file and debug this program to get converted xml file.





Note: Word document I convert in this example is DOCX file. You can also convert DOC file to xml following the above step by changing file name string in document.LoadFromFile() method.

Result Shown as Following:

Download Spire.Doc for .NET Here

Related Posts:

Convert Word to PDF

Convert HTML to PDF


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s