Linq to Xml and custom xml entities

你。 提交于 2019-12-07 16:08:25

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")

According to this thread, LINQ to XML doesn't include entity references: it doesn't have any node type for them. It just expands them as it loads a file, and after that you've just got "normal" characters.

I don't know about XDocument, but you can do it with XmlDocument:

XmlDocument doc = new XmlDocument();
var entity = doc.CreateEntityReference("InvisibleTimes");
XmlElement root = (XmlElement)doc.AppendChild(doc.CreateElement("xml"));
var el = root.AppendChild(doc.CreateElement("mo")).AppendChild(entity);
string s = doc.OuterXml;
Chris Brandsma

You may need to xml encode the names because '&' is a special character.

So instead of

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

try

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

I think you'll need a DTD to define <mo>&InvisibleTimes;</mo>.

MathML 2.0 provides an XHTML + MathML DTD.

A workaround is to use any placeholder for the & such as ;_amp_; XElement xe = new XElement("mo", ";_amp_;InvisibleTimes) and restore it when you get the xml string: output = xe.ToString().Replace(";_amp_;", "&")

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!