C#/VB.NET: Convert Word to XML

2022-05-31 07:20:00 Written by  Administrator
Rate this item
(0 votes)

XML is a markup language and file format designed mainly to store and transmit arbitrary content. XML files have the feature of simplicity, generality, and usability, making them popular, especially among web servers. XML and HTML are two important markup languages on the web, but XML focuses on storing and transmitting data while HTML focuses on displaying webpages. This article demonstrates how to convert Word documents to XML files with the help of Spire.Doc for .NET.

Install Spire.Doc for .NET

To begin with, you need to add the DLL files included in the Spire.Doc for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.

PM> Install-Package Spire.Doc

Convert a Word Document to an XML File

The detailed steps are as follows:

  • Create an object of Document class.
  • Load the Word document from disk using Document.LoadFromFile().
  • Save the Word document as an XML file using Document.SaveToFile().
  • C#
  • VB.NET
using System;
using Spire.Doc;

namespace WordtoXML
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Create an object of Document class
            Document document = new Document();

            //Load a Word document from disk
            document.LoadFromFile(@"D:\testp\test.docx");

            //Save the Word document as an XML file
            document.SaveToFile("Sample.xml", FileFormat.Xml);
        }
    }
}

C#/VB.NET: Convert Word to XML

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

Additional Info

  • tutorial_title:
Last modified on Wednesday, 31 May 2023 08:40
More in this category: C#: Convert Word to PDF »