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 / Add-ons & Links / XML Capabilities / Exporting XML /

Export

You can export XML data from Mathematica using the standard Export function.

    Export[file, expr]

    Export[file, expr, format]

The first argument of the function specifies the file to which the data should be exported. The second argument specifies the data to be exported. For exporting XML data, this can be a SymbolicXML expression or any other Mathematica expression. You can also specify an optional third argument to control the form of the output. For exporting XML data, the relevant file formats are "XML", "NotebookML", "ExpressionML", "MathML", and "SVG".

With "XML" as the export format, all expressions are imported as NotebookML or ExpressionML.

In[1]:=

Out[1]=

In[2]:=

<?xml version='1.0'?>

<!DOCTYPE Expression SYSTEM 'http://www.wolfram.com/XML/notebookml1.dtd'>

<Expression xmlns:mathematica='http://www.wolfram.com/XML/'

xmlns='http://www.wolfram.com/XML/'>

<Function>

<Symbol>Power</Symbol>

<Symbol>x</Symbol>

<Number>2</Number>

</Function>

</Expression>

With "MathML" specified as the export format, the same expression is written out as MathML.

In[3]:=

Out[3]=

In[4]:=

<math xmlns='http://www.w3.org/1998/Math/MathML'>

<semantics>

<msup>

<mi>x</mi>

<mn>2</mn>

</msup>

<annotation-xml encoding='MathML-Content'>

<apply>

<power/>

<ci>x</ci>

<cn type='integer'>2</cn>

</apply>

</annotation-xml>

</semantics>

</math>

If Export is used with only two arguments, Mathematica determines the export format based on the filename extension. The ".xml" extension is associated with XML. Hence, Export[filename.xml, expr] is equivalent to Export[filename.xml, expr, "XML"], as seen in the example below.

In[5]:=

Out[5]=

In[6]:=

<?xml version='1.0'?>

<!DOCTYPE Expression SYSTEM 'http://www.wolfram.com/XML/notebookml1.dtd'>

<Expression xmlns:mathematica='http://www.wolfram.com/XML/'

xmlns='http://www.wolfram.com/XML/'>

<Function>

<Symbol>Power</Symbol>

<Symbol>x</Symbol>

<Number>2</Number>

</Function>

</Expression>

The .mml extension is associated with MathML. Hence, Export[filename.mml, expr] is equivalent to Export[filename.mml, expr, "MathML"], as seen in the example below.

In[7]:=

Out[7]=

In[8]:=

<math xmlns='http://www.w3.org/1998/Math/MathML'>

<semantics>

<msup>

<mi>x</mi>

<mn>2</mn>

</msup>

<annotation-xml encoding='MathML-Content'>

<apply>

<power/>

<ci>x</ci>

<cn type='integer'>2</cn>

</apply>

</annotation-xml>

</semantics>

</math>

You can control the various details of the export process using the ConversionOptions feature of the Export function. For more information, see XML Export Conversion Options.

The following commands delete the test files "test.xml" and "test.mml" created by evaluating the commands in this section.

In[9]:=