Search code examples
c#xmllinqmathml

Linq to Xml and custom xml entities


I want to create a MathML document from an expression tree using Linq to xml, but I cannot figure out how to use the MathML xml entities (such as ⁡ and &InvisibleTimes): When I try to create directly a XElement using

XElement xe = new XElement("mo", "&InvisibleTimes");

it justs escapes the ampersand (which is no good). I also tried to use XElement.Parse

XElement xe = new XElement.Parse("<mo>&InvisibleTimes</mo>");

but it fails with an System.XmlException: Reference to undeclared entity 'InvisibleTimes' How can I declare the entity or ignore the checks?


Solution

  • As others have pointed out, there is no direct way to do it.

    That said, you can try using the corresponding unicode caracther. According to http://www.w3.org/TR/MathML2/mmlalias.html, for ApplyFunction it is 02061, try new XElement("mo", "\u02061")