Simple API for XML (SAX) is
a lexical, event-driven interface in which a document is read serially and its
contents are reported as callbacks to various methods on a handler
object of the user's design. SAX is fast and efficient to
implement, but difficult to use for extracting information at random from the
XML, since it tends to burden the application author with keeping track of what
part of the document is being processed. It is better suited to situations in
which certain types of information are always handled the same way, no matter
where they occur in the document.
Pull
Parsing.
Pull parsing treats the
document as a series of items which are read in sequence using the Iterator design pattern. This allows for writing of recursive-descent parsers in which the structure of the code performing the parsing
mirrors the structure of the XML being parsed, and intermediate parsed results
can be used and accessed as local variables within the methods performing the
parsing, or passed down (as method parameters) into lower-level methods, or
returned (as method return values) to higher-level methods. Examples of pull
parsers include StAX in the Java programming language, XML PullParser in Smalltalk, XML Reader in PHP, ElementTree.iterparse in Python,
System.Xml.XmlReader in the .NET
Framework, and the DOM traversal API (NodeIterator
and TreeWalker). A pull parser creates an iterator that sequentially visits the
various elements, attributes, and data in an XML document. Code which uses this
iterator can test the current item (to tell, for example, whether it is a start
or end element, or text), and inspect its attributes (local name, namespace, values of XML attributes, value of text, etc.), and can
also move the iterator to the next item. The code can thus extract information
from the document as it traverses it. The recursive-descent approach tends to
lend itself to keeping data as typed local variables in the code doing the
parsing, while SAX, for instance, typically requires a parser to manually
maintain intermediate data within a stack of elements which are parent elements
of the element being parsed. Pull-parsing code can be more straightforward to
understand and maintain than SAX parsing code.
Document
Object Model.
The Document Object Model (DOM) is an interface-oriented application
programming interface that allows for navigation of the entire document as if
it were a tree of node objects
representing the document's contents. A DOM
document can be created by a parser, or can be generated manually by users
(with limitations). Data types in DOM nodes are abstract; implementations
provide their own programming language-specific bindings. DOM implementations tend to be memory intensive, as they generally require the entire document
to be loaded into memory and constructed as a tree of objects before access is
allowed.
Data
binding.
Another form of XML processing API is XML data binding, where
XML data are made available as a hierarchy of custom, strongly typed classes,
in contrast to the generic objects created by a Document Object Model parser. This approach simplifies code development, and in
many cases allows problems to be identified at compile time rather than
run-time. Example data binding systems include the Java Architecture for XML
Binding (JAXB) and XML Serialization in .NET.
XML As
Data Type.
XML has appeared as a first-class data type in other languages. The ECMAScript
for XML (E4X) extension to the ECMAScript/JavaScript language explicitly defines two specific
objects (XML and XMLList) for JavaScript, which support XML document nodes and
XML node lists as distinct objects and use a dot-notation specifying
parent-child relationships. E4X is supported by the Mozilla 2.5+
browsers (though now deprecated) and Adobe Actionscript, but has not been adopted more universally. Similar
notations are used in Microsoft's LINQ implementation
for Microsoft .NET 3.5 and above, and in Scala (which uses the Java VM). The open-source xmlsh
application, which provides a Linux-like shell with special features for XML
manipulation, similarly treats XML as a data type, using the <[ ]>
notation. The Resource Description Framework defines a data type rdf:XMLLiteral
to hold wrapped, canonical XML.
History.
XML is
an application profile of SGML (ISO 8879).
The versatility of SGML for
dynamic information display was understood by early digital media publishers in
the late 1980s prior to the rise of the Internet. By the mid-1990s some
practitioners of SGML had gained experience with the then-new World Wide Web, and believed that SGML
offered solutions to some of the problems the Web was likely to face as it
grew. Dan Connolly added SGML to the list of W3C's
activities when he joined the staff in 1995; work began in mid-1996 when Sun
Microsystems engineer Jon Bosak
developed a charter and recruited collaborators. Bosak was well connected in
the small community of people who had experience both in SGML and the Web. XML was compiled by a working group of eleven members, supported by a (roughly) 150-member Interest
Group. Technical debate took place on the Interest Group mailing list and
issues were resolved by consensus or, when that failed, majority vote of the
Working Group. A record of design decisions and their rationales was compiled
by Michael
Sperberg-McQueen on December 4, 1997. James
Clark served as Technical Lead of the Working Group, notably
contributing the empty-element "<empty />" syntax and the name
"XML". Other names that had been put forward for consideration
included "MAGMA" (Minimal Architecture for Generalized Markup
Applications), "SLIM" (Structured Language for Internet Markup) and
"MGML" (Minimal Generalized Markup Language). The co-editors of the
specification were originally Tim
Bray and Michael
Sperberg-McQueen. Halfway through the project Bray
accepted a consulting engagement with Netscape, provoking vociferous protests from Microsoft. Bray was
temporarily asked to resign the editorship. This led to intense dispute in the
Working Group, eventually solved by the appointment of Microsoft's Jean Paoli as a third co-editor. The XML Working Group never met
face-to-face; the design was accomplished using a combination of email and
weekly teleconferences. The major design decisions were reached in a short
burst of intense work between August and November 1996, when the first Working Draft of an XML
specification was published. Further
design work continued through 1997, and XML 1.0 became a W3C Recommendation on February 10, 1998.
Sources.
XML is a profile of an ISO standard SGML, and most of XML
comes from SGML unchanged. From SGML comes the separation of logical and
physical structures (elements and entities), the availability of grammar-based
validation (DTDs), the separation of data and metadata (elements and
attributes), mixed content, the separation of processing from representation (processing
instructions), and the default angle-bracket
syntax. Removed were the SGML declaration (XML has a fixed delimiter set and
adopts Unicode as the document character
set). Other sources of technology for XML were the Text Encoding Initiative (TEI), which defined a profile of SGML for use as a
"transfer syntax"; and HTML, in which elements were synchronous with their resource,
document character sets were separate from resource encoding, the xml:lang
attribute was invented, and (like HTTP) metadata accompanied the resource rather than being
needed at the declaration of a link. The Extended Reference Concrete Syntax
(ERCS) project of the SPREAD (Standardization Project Regarding East Asian
Documents) project of the ISO-related China/Japan/Korea Document Processing
expert group was the basis of XML 1.0's naming rules; SPREAD also introduced
hexadecimal numeric character references and the concept of references to make
available all Unicode characters. To support ERCS, XML and HTML better, the
SGML standard IS 8879 was revised in 1996 and 1998 with WebSGML Adaptations.
The XML header followed that of ISO HyTime. Ideas that developed during discussion which were novel
in XML included the algorithm for encoding detection and the encoding header,
the processing instruction target, the xml:space attribute, and the new close
delimiter for empty-element tags. The notion of well-formedness as opposed to
validity (which enables parsing without a schema) was first formalized in XML,
although it had been implemented successfully in the Electronic Book Technology
"Dynatext" software the
software from the University of Waterloo New Oxford English Dictionary Project;
the RISP LISP SGML text processor at Uni-scope, Tokyo; the US Army Missile
Command IADS hypertext system; Mentor Graphics Context; Interleaf and Xerox
Publishing System.
Versions.
There are two current versions
of XML. The first (XML 1.0) was initially defined in 1998. It has
undergone minor revisions since then, without being given a new version number,
and is currently in its fifth edition, as published on November 26, 2008. It is
widely implemented and still recommended for general use. The second (XML
1.1) was initially published on February 4, 2004, the same day as XML 1.0
Third Edition, and is currently
in its second edition, as published on August 16, 2006. It contains features
(some contentious) that are intended to make XML easier to use in certain
cases. The main changes are to enable the use of line-ending characters used on
EBCDIC platforms, and the use of
scripts and characters absent from Unicode 3.2. XML 1.1 is not very widely
implemented and is recommended for use only by those who need its unique
features. Prior to its fifth edition release,
XML 1.0 differed from XML 1.1 in having stricter requirements for characters
available for use in element and attribute names and unique identifiers: in the
first four editions of XML 1.0 the characters were exclusively enumerated using
a specific version of the Unicode standard (Unicode 2.0 to Unicode 3.2.) The fifth edition
substitutes the mechanism of XML 1.1, which is more future-proof but reduces redundancy. The approach taken in the fifth edition of XML 1.0 and
in all editions of XML 1.1 is that only certain characters are forbidden in
names, and everything else is allowed, in order to accommodate the use of
suitable name characters in future versions of Unicode. In the fifth edition,
XML names may contain characters in the Balinese, Cham, or Phoenician scripts among many others which have been added to
Unicode since Unicode 3.2. Almost any Unicode code point can be used in the
character data and attribute values of an XML 1.0 or 1.1 document, even if the
character corresponding to the code point is not defined in the current version
of Unicode. In character data and attribute values, XML 1.1 allows the use of
more control characters than XML 1.0, but, for "robustness", most of
the control characters introduced in XML 1.1 must be expressed as numeric
character references (and #x7F through #x9F, which had been allowed in XML 1.0,
are in XML 1.1 even required to be expressed as numeric character references).
Among the supported control characters in XML 1.1 are two line break codes that
must be treated as whitespace. Whitespace characters are the only control codes
that can be written directly. There has been discussion of an
XML 2.0, although no organization has announced plans for work on such a
project. XML-SW (SW for skunk
works), written by one of the original developers of XML, contains some
proposals for what an XML 2.0 might look like: elimination of DTDs from syntax,
integration of namespaces, XML Base and XML
Information Set (infoset)
into the base standard.
The World Wide Web Consortium
also has an XML Binary Characterization Working Group doing preliminary
research into use cases and properties for a binary encoding of the XML
infoset. The working group is not chartered to produce any official standards.
Since XML is by definition text-based, ITU-T and ISO are using the name Fast Infoset for their own binary infoset to avoid
confusion (see ITU-T Rec. X.891 | ISO/IEC 24824-1).
Criticism.
XML and its extensions
have regularly been criticized for verbosity and complexity. Mapping the basic
tree model of XML to type systems of
programming languages or databases can be difficult, especially when XML is
used for exchanging highly structured data between applications, which was not
its primary design goal. Other criticisms attempt to refute the claim that XML
is a self-describing language (though
the XML specification itself makes no such claim). JSON, YAML,
and S-Expressions are frequently proposed as alternatives (see Comparison of data
serialization formats); which focus on representing highly structured data rather than
documents, which may contain both highly structured and relatively unstructured
content.