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 /

ImportString

You can use the standard ImportString function to import XML data from a string. This function has the following syntax.

    ImportString[string, format]

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. Here is an example of a simple XML expression converted to SymbolicXML using ImportString.

In[6]:=

Out[6]=

The three formats that Mathematica does support, 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. Here is an example of importing a simple MathML expression. Notice that the MathML markup is automatically converted to a Mathematica box expression.

In[7]:=

Out[7]=

You can stop the automatic interpretation of imported files based on file extension by specifying "SymbolicXML" as the second argument. In this example, the imported file is returned as SymbolicXML rather than the usual box expression.

In[8]:=

Out[8]=

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 ImportString function. For more information, see XML Import Conversion Options.