This is documentation for Mathematica 5, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)

Documentation / Mathematica / The Mathematica Book / A Practical Introduction to Mathematica / Files and External Operations /

1.11.7 Exchanging Material with the Web

Converting notebooks to HTML.

HTMLSave has many options that allow you to specify how notebooks should be converted for web browsers with different capabilities. You can find details in the Additional Information section of the online Reference Guide entry for HTMLSave.

Converting to and from MathML.

Here is an expression printed in MathML form.

In[1]:= MathMLForm[x^2/z]


If you paste MathML into a Mathematica notebook, Mathematica will automatically try to convert it to Mathematica input. You can copy an expression from a notebook as MathML using the Copy As menu in the notebook front end.

XML importing and exporting.

Somewhat like Mathematica expressions, XML is a general format for representing data. Mathematica automatically converts certain types of expressions to and from specific types of XML. MathML is one example. Other examples include NotebookML for notebook expressions, and SVG for graphics.

If you ask Mathematica to import a generic piece of XML, it will produce a SymbolicXML expression. Each XML element of the form <elem attr='val'>data</elem> is translated to a Mathematica SymbolicXML expression of the form XMLElement["elem", "attr"->"val", data]. Once you have imported a piece of XML as SymbolicXML, you can use Mathematica's powerful symbolic programming capabilities to manipulate the expression you get. You can then use Export to export the result in XML form.

This generates a SymbolicXML expression, with an XMLElement representing the a element in the XML string.

In[2]:= ImportString["<a aa='va'>s</a>", "XML"]


There are now two nested levels in the SymbolicXML.

In[3]:= ImportString[
"<a><b bb='1'>ss</b><b bb='2'>ss</b></a>", "XML"]


This does a simple transformation on the SymbolicXML.

In[4]:= %/."ss" -> XMLElement["c",{},{"xx"}]


This shows the result as an XML string.

In[5]:= ExportString[%, "XML"]