Arthur Ralfs
2005-11-21 23:09:27 UTC
Hello,
I'm trying to retrieve <mrow><msup><mi>x</mi><mn>2</mn></msup></mrow>
using XMLHttpRequest and insert it into a <math> element. So far with
no success.
I can do what I want with an ordinary html table element (using firefox
1.5rc3) with the
following script:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN"
"http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd"
[ <!ENTITY mathml "http://www.w3.org/1998/Math/MathML"> ] >
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:m="&mathml;">
<head>
<title>Request Test</title>
<script type="text/javascript" language="javascript">
var http_request = false;
function makeRequest(url) {
http_request = false;
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
}
if (!http_request) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}
http_request.onreadystatechange = alertContents;
http_request.overrideMimeType("text/xml");
http_request.open('GET', url, true);
http_request.send(null);
}
function getTextVersion(XMLnode) {
var text;
var serializer = new XMLSerializer();
text = serializer.serializeToString(XMLnode);
return text;
}
function alertContents() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
var xmldoc = http_request.responseXML;
var tablenodes = xmldoc.getElementsByTagName('table');
document.getElementById('foo').innerHTML = getTextVersion(tablenodes[0]);
}
}
}
</script>
</head>
<body>
<span style="cursor: pointer; text-decoration: underline;" onclick="makeRequest('tabletest.xml')">
Make a request
</span>
<div id="foo"></div>
</body>
</html>
which references the following file "tabletest.xml":
<?xml version="1.0" ?>
<root>
<table>
<tr><td>1</td><td>2</td></tr>
<tr><td>3</td><td>4</td></tr>
</table>
</root>
However when I try the same thing with the mathml it doesn't work. Any
suggestions would be greatly appreciated.
To be absolutely precise I include the script and xml I try with mathml,
although mostly it's the same.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN"
"http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd"
[ <!ENTITY mathml "http://www.w3.org/1998/Math/MathML"> ] >
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:m="&mathml;">
<head>
<title>Request Test</title>
<script type="text/javascript" language="javascript">
var http_request = false;
function makeRequest(url) {
http_request = false;
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
}
if (!http_request) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}
http_request.onreadystatechange = alertContents;
http_request.overrideMimeType("text/xml");
http_request.open('GET', url, true);
http_request.send(null);
}
function getTextVersion(XMLnode) {
var text;
var serializer = new XMLSerializer();
text = serializer.serializeToString(XMLnode);
return text;
}
function alertContents() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
var xmldoc = http_request.responseXML;
var mrownodes = xmldoc.getElementsByTagName('mrow');
document.getElementById('foo').innerHTML = getTextVersion(mrownodes[0]);
}
}
}
</script>
</head>
<body>
<span style="cursor: pointer; text-decoration: underline;" onclick="makeRequest('mathtest.xml')">
Make a request
</span>
<m:math id="foo" xmlns="&mathml;" mathsize="big" display="block"></m:math>
</body>
and the xml file:
<?xml version="1.0" ?>
<root>
<mrow><msup><mi>x</mi><mn>2</mn></msup></mrow>
</root>
</html>
Thanks
Arthur Ralfs
I'm trying to retrieve <mrow><msup><mi>x</mi><mn>2</mn></msup></mrow>
using XMLHttpRequest and insert it into a <math> element. So far with
no success.
I can do what I want with an ordinary html table element (using firefox
1.5rc3) with the
following script:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN"
"http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd"
[ <!ENTITY mathml "http://www.w3.org/1998/Math/MathML"> ] >
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:m="&mathml;">
<head>
<title>Request Test</title>
<script type="text/javascript" language="javascript">
var http_request = false;
function makeRequest(url) {
http_request = false;
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
}
if (!http_request) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}
http_request.onreadystatechange = alertContents;
http_request.overrideMimeType("text/xml");
http_request.open('GET', url, true);
http_request.send(null);
}
function getTextVersion(XMLnode) {
var text;
var serializer = new XMLSerializer();
text = serializer.serializeToString(XMLnode);
return text;
}
function alertContents() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
var xmldoc = http_request.responseXML;
var tablenodes = xmldoc.getElementsByTagName('table');
document.getElementById('foo').innerHTML = getTextVersion(tablenodes[0]);
}
}
}
</script>
</head>
<body>
<span style="cursor: pointer; text-decoration: underline;" onclick="makeRequest('tabletest.xml')">
Make a request
</span>
<div id="foo"></div>
</body>
</html>
which references the following file "tabletest.xml":
<?xml version="1.0" ?>
<root>
<table>
<tr><td>1</td><td>2</td></tr>
<tr><td>3</td><td>4</td></tr>
</table>
</root>
However when I try the same thing with the mathml it doesn't work. Any
suggestions would be greatly appreciated.
To be absolutely precise I include the script and xml I try with mathml,
although mostly it's the same.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN"
"http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd"
[ <!ENTITY mathml "http://www.w3.org/1998/Math/MathML"> ] >
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:m="&mathml;">
<head>
<title>Request Test</title>
<script type="text/javascript" language="javascript">
var http_request = false;
function makeRequest(url) {
http_request = false;
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
}
if (!http_request) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}
http_request.onreadystatechange = alertContents;
http_request.overrideMimeType("text/xml");
http_request.open('GET', url, true);
http_request.send(null);
}
function getTextVersion(XMLnode) {
var text;
var serializer = new XMLSerializer();
text = serializer.serializeToString(XMLnode);
return text;
}
function alertContents() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
var xmldoc = http_request.responseXML;
var mrownodes = xmldoc.getElementsByTagName('mrow');
document.getElementById('foo').innerHTML = getTextVersion(mrownodes[0]);
}
}
}
</script>
</head>
<body>
<span style="cursor: pointer; text-decoration: underline;" onclick="makeRequest('mathtest.xml')">
Make a request
</span>
<m:math id="foo" xmlns="&mathml;" mathsize="big" display="block"></m:math>
</body>
and the xml file:
<?xml version="1.0" ?>
<root>
<mrow><msup><mi>x</mi><mn>2</mn></msup></mrow>
</root>
</html>
Thanks
Arthur Ralfs