-
MathType
-
WirisQuizzes
-
Nubric
-
CalcMe
-
MathPlayer
-
Store FAQ
-
MathFlow
-
BF FAQ
-
Miscellaneous
-
Wiris Integrations
Modified XML encoding for MathML
Reading time: 1minThis article describes how MathType modifies XML characters in MathML when formulas need to be stored in contexts where raw XML cannot be used safely, such as HTML attributes or platforms that filter unrecognized XML tags.
Requirements/Prerequisites:
- MathType HTML integration.
- Access to the encoded MathML source.
- Basic familiarity with XML and MathML.
Concepts:
MathML is XML-based. In some environments, raw XML characters may be filtered, parsed incorrectly, or removed. To prevent this, MathType may replace reserved XML characters with alternative characters.
Reference details
MathType imports and exports MathML, which sometimes cannot be placed directly inside HTML files. For example, the Moodle platform filters some HTML tags (APPLET, OBJECT, EMBED, etc.) and all unrecognized XML tags, and so it removes any MathML formula. This also occurs when the MathML appears inside an HTML attribute (for example, the SRC attribute of an IMG tag) and the browser, wrongly, tries to parse it.
In these situations, the 5 reserved characters of XML are replaced by other characters, as shown in the following table:
| Original XML character | Replacing character |
|---|---|
| < (#3C) | « (#AB) |
| > (#3E) | » (#BB) |
| & (#26) | § (#A7) |
| " (#22) | ¨ (#A8) |
| ' (#27) | ` (#60) |
Then, recovering the MathML from the modified version is as simple as undoing the replacement. The following XSLT example reverses the character replacements and restores the original XML characters.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<!-- template for text -->
<xsl:template match="child::text()">
<!-- « (#AB), » (#BB), § (#A7), ¨ (#A8), ` (#B4) -->
<xsl:variable name="text" select="translate(.,'«»§¨','<>&"')"/>
<!-- ` (#B4) -->
<xsl:value-of disable-output-escaping="yes" select='translate($text,"´","'")'/>
</xsl:template>
<!-- template for other nodes (including attributes) -->
<xsl:template match="@*|*">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>