Mathematica 教程 函数 »|教程 »

# Exchanging Material with the Web

 Export["file.html",nb] save the notebook nb in HTML form

Converting notebooks to HTML.

Export has many options applying to HTML export that allow you to specify how notebooks should be converted for web browsers with different capabilities.
 MathMLForm[expr] print expr in MathML form MathMLForm[StandardForm[expr]] use StandardForm rather than traditional mathematical notation ToExpression["string",MathMLForm] interpret a string of MathML as Mathematica input

Converting to and from MathML.

Here is an expression printed in MathML form.
 Out[1]//MathMLForm=
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.
 Export["file.xml",expr] export in XML format Import["file.xml"] import from XML ImportString["string","XML"] import data from a string of XML

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. Another example is 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.
 Out[2]=
There are now two nested levels in the SymbolicXML.
 Out[3]=
This does a simple transformation on the SymbolicXML.
 Out[4]=
This shows the result as an XML string.
 Out[5]=
 Import["http://url",...] import a file from any accessible URL Import["ftp://url",...] import a file from an FTP server

Importing data from web sources.

 This imports a picture from a website.