I need a MediaWiki parser in C#.
( http://www.mediawiki.org/wiki/Alternative_parsers )
Since there exists none, and I really want a MediaWiki parser and not some other, like WikiPlex, I was looking into using some of the existing parsers in another language, and was able to successfully invoke the kiwi parser to achieve this. However, the problem is it doesn't handle Unicode/UTF-8 correctly.
Now, I wanted to use this script:
http://www.connellybarnes.com/code/python/mw2html
and use it via IronPython.
I use IronPython 2.7 from here:
http://ironpython.net/
I downloaded the binary zip file (not the installer).
Then I used this tutorial as base:
http://www.codeproject.com/KB/cs/IronPythonMethod_CShap.aspx
And this is what I did:
using System;
using IronPython.Hosting;
namespace IronPythonMethodInvokationDemo
{
class Program
{
// http://stackoverflow.com/questions/6557494/referencing-python-import-assemblies-when-calling-from-ironpython-in-c
static void Main(string[] args)
{
//Microsoft.Scripting.Hosting.ScriptEngine m_engine = Python.CreateEngine(DefaultEngineOptions());
Microsoft.Scripting.Hosting.ScriptEngine m_engine = Python.CreateEngine();
System.Collections.Generic.ICollection<string> paths = m_engine.GetSearchPaths();
paths.Add(@"D:\username\Documents\Visual Studio 2010\Projects\IronPython\IronPython-Bin-2.7\IronPython-2.7\Lib"); // modules path
paths.Add(@"D:\username\Documents\Visual Studio 2010\Projects\IronPython\IronPython-Bin-2.7\IronPython-2.7"); // ipy.exe path
m_engine.SetSearchPaths(paths);
//Step 1:
//Creating a new script runtime
//var ironPythonRuntime = Python.CreateRuntime();
var ironPythonRuntime = m_engine.Runtime;
try
{
//Step 2:
//Load the Iron Python file/script into the memory
//Should be resolve at runtime
//dynamic loadIPython = ironPythonRuntime.UseFile("first.py");
//ironPythonRuntime.GetBuiltinModule();
dynamic loadIPython = ironPythonRuntime.UseFile("mw3html.py");
//Step 3:
//Invoke the method and print the result
/*
Console.WriteLine(
string.Format("Addition result from IronPython method for {0} and {1} is {2}",
100,200, loadIPython.add(100, 200))
);
*/
Console.WriteLine( string.Format("Result for IronPython main method: {0}", loadIPython.main()) );
} // End Try
catch (System.IO.FileNotFoundException ex)
{
Console.WriteLine(ex.Message);
} // End Catch
Console.ReadKey(true);
} // End Sub Main
} // End Class Program
} // End Namespace IronPythonMethodInvokationDemo
If I use first.py, then everything works fine. Now, using mw2html.py, I get a
KeyNotFoundException on ironPythonRuntime.UseFile("mw3html.py"); for key "" ...
Anybody knows what that means?