Manual:XML Import file manipulation in CSharp

Overview
This page shows how to use the MediaWiki schema with Visual Studio .NET C# to manipulate a Media Wiki XML import file in code.

One use case for this is that you might have a number of pages in a wiki site that need to be modified. One way to do this is to export them to an XML file, then manipulate the XML file, and then import the XML file back. Of course, you should be sure that users cannot modify these files during the span between export and re-import. For sites with moderate usage, this approach might be appropriate.

Schema
First, download the Media Wiki schema at http://www.mediawiki.org/xml/export-0.3.xsd. Using Visual Studio.NET's "xsd.exe" tool, you can generate .NET class files based on this schema using this VS.NET command line prompt:

xsd c:/export-0.3.xsd /c

.NET Project
Next, place the auto-generated class file in a .NET project, such as a console application project.

In this code sample, you will see examples of how to work with the XML file in an object-oriented way instead of parsing the raw XML. Note that this code sample below was used for the 1.13.2 version of Media Wiki.