11.07.2015 Views

webMathematica™ Wolfram - Wolfram Research

webMathematica™ Wolfram - Wolfram Research

webMathematica™ Wolfram - Wolfram Research

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

webMathematica User Guide 135You can test this with the URL http://localhost:8080/webMathematica/Examples/AJAX/ReturnXML.jsp?num=8. You should see something like the following.27325171This is a simple XML fragment made up for this example. The root tag is factors and it containssequences of factor and exponent tags. This might be improved if each pair of factorand exponent tags were placed in a containing tag. The current approach is taken to keep thecode simple.Note how the XML is created by first making an XMLElement expression, and then convertingthis to a textual representation of the XML with ExportString. An alternative would be to uselots of string concatentation operations. It is very strongly recommended to use the symbolicXML technology of XMLElement. Symbolic XML will be much more robust, since a coding errorwill not lead to a string of ill-formed XML. It will also be much more flexible, if you want tochange one of the tags it will be easier. Also, it is convenient to use other XML features such asattributes or namespaces. Mathematica provides some very nice tools for working with XML andit is extremely good to use them.Here is part of the JavaScript function in LoadXML.jsp. It shows how the XML result is extractedfrom the HTTP result and arrays of factor and exponent tags are obtained. The result is thenformatted into an HTML table, which is then inserted into the final page.xmlHttp.onreadystatechange = function() {if(xmlHttp.readyState == 4) {var xmlData = xmlHttp.responseXML;var rootNode = xmlData.getElementsByTagName('factors')[0];var factorList = rootNode.getElementsByTagName('factor');var exponentList = rootNode.getElementsByTagName('exponent');var newHTML = "";var num = document.getElementById("inputvalue").value;newHTML = newHTML + "Factorization of " +num + "! ";newHTML = newHTML + "FactorExponent";for ( var i = 0; i < factorList.length; i++) {newHTML = newHTML + "";

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!