我正在使用MathML DTD和System.Xml.Linq
解析MathML。虽然普通的MathML可以被正确识别,但是DTD中的MMLEXTRA
被忽略了,导致出现错误。这是我使用的代码:
if (!string.IsNullOrWhiteSpace(mathML))
{
try
{
const string preamble =
"<!DOCTYPE mml:math PUBLIC \"-//W3C//DTD MathML 2.0//EN\"\n" +
"\"http://www.w3.org/Math/DTD/mathml2/mathml2.dtd\" [\n" +
"<!ENTITY % MATHML.prefixed \"INCLUDE\">\n" +
"<!ENTITY % MATHML.prefix \"mml\"> \n" +
"]>";
var parsed = Parser.Parse(preamble + Environment.NewLine + mathML);
textEditor.Text = printed;
lblStatus.Caption = "MathML successfully translated.";
}
catch (Exception e)
{
lblStatus.Caption = "Cannot translate text. " + e.Message;
}
}
解析器只需执行
XDocument.Load()
。需要任何帮助!
Parser
只是一个基本上执行XDocument.Load
的组件。假设这个调用会直接解析所有的MathML引用,但实际上并不是这样。 - Dmitri Nesteruk