|
SymbolicXML
SymbolicXML is the format used by Mathematica for representing XML documents. The conversion from XML to SymbolicXML translates the XML document into a Mathematica expression, while preserving its structure. Since both XML documents and Mathematica expressions have a tree structure, there is a natural mapping from one to the other. You can then manipulate the SymbolicXML expression using the standard techniques of Mathematica programming.
You can import XML data into Mathematica using the standard Import or ImportString functions. You can also control 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. For more information, see XML Import Conversion Options.
The following command imports an XML data file into Mathematica.
Import["data.xml","XML"]
The result is a SymbolicXML expression, expr1, which you can then manipulate using standard Mathematica commands. The end result of your transformations is another SymbolicXML expression, expr2.
expr1 expr2
Finally, you can export the result as an XML file using the standard Export function.
Export["newdata.xml",expr2,"XML"]
You can use conversion options to control various details of the export process, such as the format of the exported XML, with the ConversionOptions feature of the Export function. For more information, see XML Export Conversion Options.
The combination of SymbolicXML and Mathematica programming provides a useful alternative to other techniques for manipulating XML documents, such as XSLT transformations or the SAX or DOM APIs used with a low-level programming language such as Java. Mathematica allows you to achieve the same level of flexibility and control in processing XML documents. The advantage is that you can leverage Mathematica's advanced support for symbolic manipulation and numerical computation to do some very complex and sophisticated transformations that would be difficult or impossible to do using other methods.
For example, you can use pattern-matching techniques to extract specific parts of an XML document, perform numerical computations on the data, and then convert the results into 3D graphics for easy visualization. You can also define transformations to convert one type of XML application to another. For example, you can import a DocBook document as SymbolicXML and then convert it into XHTML format by defining suitable transformation rules to replace one set of element names with another set. For some specific examples of useful applications of SymbolicXML, see Transforming XML.
Support for SymbolicXML is well-integrated with NotebookML, ExpressionML and MathML. For example, when importing an XML document as SymbolicXML, Mathematica recognizes if the document is in NotebookML, ExpressionML, or MathML format and automatically converts it into a notebook expression in the case of NotebookML, an expression in the case of ExpressionML, or a typeset box expression in the case of MathML. You can also override the default behavior and choose to import any of these XML flavors as SymbolicXML if you wish. There are also a large number of kernel functions for quickly and easily converting between strings, boxes, or expressions on the one hand, and NotebookML, MathML or SymbolicXML on the other.
Note that if you prefer to manipulate XML documents using Java directly, you can still do so using a J/Link add-on package. This package integrates Mathematica fully with Java, enabling you to call Java commands from Mathematica or to call Mathematica kernel functions from Java programs. You can thus have access to both the computational abilities of Mathematica as well as the low-level programming features and classes of Java, combining the two as needed.
|