Manual:XML Import file manipulation in CSharp/ja

概要
このページでは、Visual Studio .NET C# でMediWiki XML 取り込みファイルを操作する場合に、生の XML の直接操作の代わりにオブジェクト指向のプログラミングを使用したコードで、MediaWiki スキーマを使用する方法を示します.

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.

スキーマ
As shown in this abbreviated example of an XML import file below, the schemaLocation of the XML file is at https://www.mediawiki.org/xml/export-0.3.xsd:

First, download the MediaWiki schema at https://www.mediawiki.org/xml/export-0.3.xsd. Place the schema file in a .NET project folder, and consider renaming the file to something more intuitive such as MediaWikiExport.xsd. Using Visual Studio.NET's xsd.exe tool, you can generate a .NET class file based on this schema using this VS.NET command line prompt:  xsd c:/inetpub/wwwroot/MyProject/MediaWikiExport.xsd /c このコマンドで MediaWikiExport.cs という名前のクラス ファイルが生成されます.

クラス図
The auto-generated Class file will look like this:

スキーマ図
スキーマは以下のようになります:

.NET プロジェクト
After you add your new auto-generated class file, add the file into your .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 MediaWiki.

C# 3.0 version
Here's the same example using C# 3.0 features, including type inference and a lambda expression.