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

Documentation / Mathematica / Add-ons & Links / XML Capabilities / Importing XML /


You can import XML data into Mathematica using the standard Import function, which has the following syntax.


    Import[file, format]

The first argument of the function specifies the file to be imported. You can also specify an optional second argument to control the form of the output. For importing XML data, the relevant file formats are: "XML", "NotebookML", "ExpressionML", "MathML", and "SymbolicXML".

With "XML" as the import format, any XML formats that Mathematica does not recognize are returned as SymbolicXML. The three formats that Mathematica does support on import, namely NotebookML, ExpressionML, and MathML, are treated slightly differently. A NotebookML file is imported as a notebook expression. An ExpressionML file is imported as the corresponding cell expression. A MathML file is returned as the corresponding box expression.

With "SymbolicXML" as the import format, even NotebookML, ExpressionML, and MathML files are imported as SymbolicXML. This gives you a way to override any interpretation beyond just importing as SymbolicXML.

Here is a file containing a simple MathML equation.


Out[1]=<math xmlns="">
<annotation-xml encoding="MathML-Content">
<cn type="integer">2</cn>

If you import the file and specify "XML" as the second argument, the equation is converted into a box expression.



If you specify "SymbolicXML" as the second argument, the equation is imported as a SymbolicXML box expression.



If Import is used with only one argument, Mathematica processes the data in the file based on its file extension. Any file with a .xml extension is imported as XML. This means that if it is in one of the XML formats explicitly supported by Mathematica, namely NotebookML, ExpressionML, or MathML the file will be interpreted in the appropriate way. All other XML formats are imported as SymbolicXML.

Mathematica also recognizes the .mml extension for MathML files and the .nbml extension for NotebookML files. In the following example, we import a file with the .mml extension.



You can display the above box expression as conventional mathematical notation by using DisplayForm.



You can control the various details of the import process, such as how to treat whitespace, whether to recognize entities, or whether to validate against a DTD, by specifying conversion options to the Import function. For more information, see XML Import Conversion Options.