private void extractMathExpressions(WordprocessingDocument doc) { Body docBody = doc.MainDocumentPart.Document.Body; List <OfficeMath> mathExpressions = new List <OfficeMath>(docBody.Descendants <OfficeMath>()); parsedExpressions.Clear(); foreach (var expression in mathExpressions) { try { var tokenTree = tokenTreeBuilder.build(expression); var syntaxTree = syntaxTreeBuilder.Build(tokenTree); parsedExpressions.Add(new OpenXMLExpression(expression, syntaxTree)); } catch (Exception ex) { } } }
static void Main(string[] args) { String docPath = @"..\..\proba - Copy.docx"; WordprocessingDocument doc = WordprocessingDocument.Open(docPath, false); Body docBody = doc.MainDocumentPart.Document.Body; ParseProperties parseProperties = buildProperties(); TokenTreeBuilder tokenTreeBuilder = new TokenTreeBuilder(parseProperties); SyntaxTreeBuilder syntaxTreeBuilder = new SyntaxTreeBuilder(parseProperties); List <OfficeMath> mathExpressions = new List <OfficeMath>(docBody.Descendants <OfficeMath>()); foreach (var expression in mathExpressions) { if (String.IsNullOrWhiteSpace(expression.InnerText)) { continue; } Console.WriteLine("OMath paragraph found!"); Console.WriteLine(System.Xml.Linq.XDocument.Parse(expression.OuterXml).ToString()); TokenTree tokenTree = tokenTreeBuilder.build(expression); SyntaxTree syntaxTree = syntaxTreeBuilder.Build(tokenTree); Console.WriteLine("\nSyntax tree built!"); Console.WriteLine("Postfix notation: "); Console.WriteLine(syntaxTree.toPostfixNotation()); Console.WriteLine("Infix notation: "); Console.WriteLine(syntaxTree.toInfixNotation()); Console.WriteLine("\n====================================================================\n"); } Console.Read(); }