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 / Working with NotebookML /

Introduction

NotebookML is an XML format for describing Mathematica notebooks. It involves a mapping of a notebook expression to a similar XML tree structure. The names of elements and attributes in NotebookML are chosen to match the names of the corresponding parts of the original notebook expression. Let us look at an example.

Here is a simple notebook expression.

Notebook[{Cell["Here is some text!","Text"]}]

Here is the same expression in NotebookML.

<Notebook>

<List>

<Cell>

<String>This is a cell.</String>

<Style>

<String>Section</String>

</Style>

</Cell>

</List>

</Notebook>

Note the direct correspondence between the parts of the notebook expression and their XML counterparts. The conversion is done on the FullForm of the notebook expression. For example, while a list can be denoted by {} in a notebook, the underlying representation of the list is still List[...]. Hence, in NotebookML a list would be represented by a List element of the form: <List>...</List>.

NotebookML is useful for exporting complete notebooks in XML format. However, you can also export individual cells, mathematical formulas, or other types of content in a notebook as XML, using what is called ExpressionML. This is a subset of NotebookML that enables you to save arbitrary Mathematica expressions in XML format. Let us look at an example. Here is the FullForm for a mathematical formula.

In[1]:=

Out[1]//FullForm=

Here is the ExpressionML representation of the same formula. You can generate the NotebookML or ExpressionML for any type of notebook expression using Export or ExportString.

<Expression>

<Function>

<Symbol>Sin</Symbol>

<Function>

<Symbol>Plus</Symbol>

<Number>1</Number>

<Symbol>x</Symbol>

</Function>

</Function>

</Expression>

NotebookML and ExpressionML are both 100 percent well-formed, standards-compliant XML. Hence, they make it easy to integrate Mathematica notebooks or parts of notebooks into any XML framework or workflow.