user10423802
user10423802

Reputation:

c# Identify the ChildNode of the XmlDocument that load MathML

I read math tag in MahtML through the LoadXml(string xml) method in class XmlDocument.

The main reason why I posted this question is

Like Child in the 'DocumentFormat.OpenXml.OpenXml.OpenXmlElement' class in the 'Open-XmlElement' class of 'Open-XML-SDK' that reads Office (word, powerpoint, excel, etc...) I want to know if the tag is a fraction, molecule, denominator, square root, or subscript.

Is there a way for 'ChildNode' in 'XmlDocument' to write source code like the example code below? Please help

foreach(var child in node.ChildElements) // `node` is OpenXmlElement class
{
    if(child is OMath.Run) { }
    else if(child is OMath.Fraction) { }
    else if(child is OMath.Numerator) { }
    else if(child is OMath.Denominator) { }
    else if(child is OMath.Radical) { }
    else if(child is OMath.SuperArgument) { }
    else if(child is OMath.SubArgument) { }
    else if(child is OMath.Delimiter) { }
    else if(child is OMath.FractionProperties) { }
}

my code:

using System.Xml;

string mathml = @"<math xmlns='http://www.w3.org/1998/Math/MathML'><mfrac><mrow><mo>−</mo><mi>b</mi><mo>±</mo><msqrt><mrow><msup><mi>b</mi><mn>2</mn></msup><mo>−</mo><mn>4</mn><mi>a</mi><mi>c</mi></mrow></msqrt></mrow><mrow><mn>2</mn><mi>a</mi></mrow></mfrac></math>";
XmlDocument doc = new XmlDocument();
doc.LoadXml(mathml);
ReadNode(doc.ChildNodes);

private void ReadNode(XmlNodeList nodeList)
{
    foreach (XmlNode n in nodeList)
    {
        Debug.WriteLine($"{n} type is denominator(ex"); //For example
        ReadNode(n.ChildNodes);
    }
}

Please understand my poor English skills.

Upvotes: 0

Views: 40

Answers (0)

Related Questions