This is documentation for Mathematica 6, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)
Mathematica Import/Export Format

XML (.xml)

MIME type: text/xml
XML general-purpose markup language and structured document format.
Primarily used for the exchange of data across different systems in computer networks.
Uses a hierarchical model for the representation of structured data.
Stores data in a tree-based structure consisting of markup tags, attributes, and character contents.
Plain text file, normally encoded as UTF-8.
XML is an acronym derived from Extensible Markup Language.
Is a subset of the Standard Generalized Markup Language (SGML).
Developed since 1996 by the XML Working Group.
Published in 2001 as W3C standard recommendation RFC 3076.
  • Import and Export fully support the XML standard Version 1.0.
  • Import["file.xml"] imports an XML file and returns an XMLObject expression.
  • Since both XML and Mathematica represent data as a tree structure, there is a natural mapping from one to the other. Mathematica stores XML data structures as nested XMLElement objects, and an entire XML document as XML data embedded in an XMLObject.
  • Import["file.xml"] returns an XMLObject expression, representing the entire XML document in symbolic form as a tree of XMLElement expressions.
  • Import by default returns numeric data stored in XML as strings.
  • Import["file.xml", elem] imports the specified element from an XML file.
  • Import["file.xml", {elem, suba, subb, ...}] imports a subelement.
  • Import["file.xml", {{elem1, elem2, ...}}] imports multiple elements.
  • The import format can be specified with Import["file", "XML"] or Import["file", {"XML", elem, ...}].
  • Export["file.xml", expr, elem] creates an XML file by treating expr as specifying element elem.
  • Export["file.xml", {expr1, expr2, ...}, {{elem1, elem2, ...}}] treats each expri as specifying the corresponding elemi.
  • Export["file.xml", expr, opt1->val1, ...] exports expr with the specified option elements taken to have the specified values.
  • Export["file.xml", {elem1->expr1, elem2->expr2, ...}, "Rules"] uses rules to specify the elements to be exported.
  • See the reference pages for full general information on Import and Export.
"Elements"list of elements and options available in this file
"Rules"full list of rules for each element and option
"Options"list of rules for options, properties and settings
  • Data representation elements:
"CDATA"CDATA sections as a list of strings
"Comments"XML comments as a list of strings
"EmbeddedDTD"DTD included in the XML document
"Plaintext"a plain text representation of the file
"Tags"list of all tags occurring in the file
"XMLObject"entire document as a symbolic XML expression
"XMLElement"nested XMLElement objects
  • Import uses the "XMLObject" element by default.
"AllowRemoteDTDAccess"Truewhether to attempt to retrieve an external DTD over a network
"AllowUnrecognizedEntities"Automaticwhether to allow parsing to work around unrecognized entities in the XML document
"IncludeDefaultedAttributes"Falsewhether to fill in default values for attributes
"IncludeEmbeddedObjects"Noneembedded objects (of "Comments" and "ProcessingInstructions") to include
"IncludeNamespaces"Automaticwhether to return fully qualified tag and attribute names
"NormalizeWhiteSpace"Automaticwhether to remove leading and trailing whitespace and to reduce consecutive spaces to a single space in character data
"PreserveCDATASections"Falsewhether to preserve character data sections as special objects
"ReadDTD"Truewhether to read an external DTD
"ValidateAgainstDTD"Automaticwhether to validate the document against the specified DTD
"AttributeQuoting""'"specifies the delimiter for attribute values
"ElementFormatting"Automaticindentation of elements and line breaking of long strings in the exported document
"Entities"Nonerules for replacing characters with named entities
"NamespacePrefixes"{}namespace prefix designations, of the form "namespace"->"prefix"