此为 Mathematica 8 文档,内容基于更早版本的 Wolfram 语言
查看最新文档(版本11.1)

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 uses a specific Import converter for XML-based file formats if possible, otherwise it imports the file as generic XML and returns an XMLObject expression.
  • Import["file.xml", "XML"] always imports as generic XML.
  • 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 imports the specified element from an XML file.
  • Import imports multiple elements.
  • The import format can be specified with Import["file", "XML"] or Import.
  • Import["file.html", "XML"] converts HTML to well-formed XML before importing.
  • Export creates an XML file by treating expr as specifying element elem.
  • Export treats each as specifying the corresponding .
  • Export exports expr with the specified option elements taken to have the specified values.
  • Export 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 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 and ) to include
"IncludeNamespaces"Automaticwhether to return fully qualified tag and attribute names
"NormalizeWhitespace"Automaticwhether to remove leading and trailing whitespace and 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
Import an XML sample file as symbolic XML:
Show the Import elements available in this file:
Import all CDATA sections:
Convert to plain text:
Get the list of all XML tags that occur in this sample file:
Import an XML sample file as symbolic XML:
In[1]:=
Click for copyable input
Out[1]=
Show the Import elements available in this file:
In[2]:=
Click for copyable input
Out[2]=
Import all CDATA sections:
In[3]:=
Click for copyable input
Out[3]=
Convert to plain text:
In[4]:=
Click for copyable input
Out[4]=
Get the list of all XML tags that occur in this sample file:
In[5]:=
Click for copyable input
Out[5]=