Overview
The main purpose of XML is serialization, i.e. storing, transmitting, and reconstructing arbitrary data. For two disparate systems to exchange information, they need to agree upon a file format. XML standardizes this process. It is therefore analogous to aapplication/xml
(text/xml
is an alias), application/xml-external-parsed-entity
(text/xml-external-parsed-entity
is an alias) and application/xml-dtd
. They are used for transmitting raw XML files without exposing their internal +xml
, for example, image/svg+xml
for SVG.
Further guidelines for the use of XML in a networked context appear in RFC 3470, also known as IETF BCP 70, a document covering many aspects of designing and deploying an XML-based language.
Applications
XML has come into common use for the interchange of data over the Internet. Hundreds of document formats using XML syntax have been developed, including RSS,Key terminology
The material in this section is based on the XML Specification. This is not an exhaustive list of all the constructs that appear in XML; it provides an introduction to the key constructs most often encountered in day-to-day use. ;: An XML document is a string of ''characters''. Every legal<
and end with a >
, or they begin with the character &
and end with a ;
. Strings of characters that are not markup are content. However, in a CDATA section, the delimiters <! and ">DATA[
and "> and
>
are classified as markup, while the text between them is classified as content. In addition, whitespace before and after the outermost element is classified as markup.
;: A ''tag'' is a markup construct that begins with <
and ends with >
. There are three types of tag:
:* ''start-tag'', such as <section>
;
:* ''end-tag'', such as </section>
;
:* ''empty-element tag'', such as <line-break />
.
;: An ''element'' is a logical document component that either begins with a start-tag and ends with a matching end-tag or consists only of an empty-element tag. The characters between the start-tag and end-tag, if any, are the element's ''content'', and may contain markup, including other elements, which are called ''child elements''. An example is <greeting>Hello, world!</greeting>
. Another is <line-break />
.
;: An ''attribute'' is a markup construct consisting of a name–value pair that exists within a start-tag or empty-element tag. An example is <img src="madonna.jpg" alt="Madonna" />
, where the names of the attributes are "src" and "alt", and their values are "madonna.jpg" and "Madonna" respectively. Another example is <step number="3">Connect A to B.</step>
, where the name of the attribute is "number" and its value is "3". An XML attribute can only have a single value and each attribute can appear at most once on each element. In the common situation where a list of multiple values is desired, this must be done by encoding the list into a well-formed XML attribute with some format beyond what XML defines itself. Usually this is either a comma or semi-colon delimited list or, if the individual values are known not to contain spaces, a space-delimited list can be used. An example with space as a delimiter is <div class="inner greeting-box">Welcome!</div>
, where the attribute "class" both has the value "inner greeting-box" and also indicates the two CSS class names "inner" and "greeting-box".
;: XML documents may begin with an ''XML declaration'' that describes some information about themselves. An example is <?xml version="1.0" encoding="UTF-8"?>
.
Characters and escaping
XML documents consist entirely of characters from theValid characters
Unicode code points in the following ranges are valid in XML 1.0 documents: * U+0009 (Horizontal Tab), U+000A (Line Feed), U+000D (Carriage Return): these are the only C0 controls accepted in XML 1.0; * U+0020–U+D7FF, U+E000–U+FFFD: this excludes some noncharacters in the BMP (all surrogates, U+FFFE and U+FFFF are forbidden); * U+10000–U+10FFFF: this includes all code points in supplementary planes, including noncharacters. XML 1.1 extends the set of allowed characters to include all the above, plus the remaining characters in the range U+0001–U+001F. At the same time, however, it restricts the use of C0 and C1 control characters other than U+0009 (Horizontal Tab), U+000A (Line Feed), U+000D (Carriage Return), and U+0085 (Next Line) by requiring them to be written in escaped form (for example U+0001 must be written as
or its equivalent). In the case of C1 characters, this restriction is a backwards incompatibility; it was introduced to allow common encoding errors to be detected.
The code point U+0000 (Null) is the only character that is not permitted in any XML 1.1 document.
Encoding detection
The Unicode character set can be encoded into bytes for storage or transmission in a variety of different ways, called "encodings". Unicode itself defines encodings that cover the entire repertoire; well-known ones include UTF-8 (which the XML standard recommends using, without a BOM) and UTF-16. There are many other text encodings that predate Unicode, such asEscaping
XML provides '' escape'' facilities for including characters that are problematic to include directly. For example: * The characters "<" and "&" are key syntax markers and may never appear in content outside a CDATA section. It is allowed, but not recommended, to use "<" in XML entity values. * Some character encodings support only a subset of Unicode. For example, it is legal to encode an XML document in ASCII, but ASCII lacks code points for Unicode characters such as "é". * It might not be possible to type the character on the author's machine. * Some characters have glyphs that cannot be visually distinguished from other characters, such as the nonbreaking space ( 
) " " and the  
) " ", and the Cyrillic capital letter A (А
) "А" and the Latin capital letter A (A
) "A".
There are five predefined entities:
* <
represents "<";
* >
represents ">";
* &
represents "&";
* '
represents "";
* "
represents ''.
All permitted Unicode characters may be represented with a '' numeric character reference''. Consider the Chinese character "中", whose numeric code in Unicode is hexadecimal 4E2D, or decimal 20,013. A user whose keyboard offers no method for entering this character could still insert it in an XML document encoded either as 中
or 中
. Similarly, the string "I <3 Jörg" could be encoded for inclusion in an XML document as I <3 Jörg
.
�
is not permitted because the null character is one of the control characters excluded from XML, even when using a numeric character reference. An alternative encoding mechanism such as Base64 is needed to represent such characters.
Comments
Comments may appear anywhere in a document outside other markup. Comments cannot appear before the XML declaration. Comments begin with<!--
and end with -->
. For compatibility with SGML, the string "--" (double-hyphen) is not allowed inside comments; this means comments cannot be nested. The ampersand has no special significance within comments, so entity and character references are not recognized as such, and there is no way to represent characters outside the character set of the document encoding.
An example of a valid comment:
<!--no need to escape <code> & such in comments-->
International use
XML 1.0 (Fifth Edition) and XML 1.1 support the direct use of almost anySyntactical correctness and error-handling
The XML specification defines an XML document as a well-formed text, meaning that it satisfies a list of syntax rules provided in the specification. Some key points include: * The document contains only properly encoded legal Unicode characters. * None of the special syntax characters such as<
and &
appear except when performing their markup-delineation roles.
* The start-tag, end-tag, and empty-element tag that delimit elements are correctly nested, with none missing and none overlapping.
* Tag names are case-sensitive; the start-tag and end-tag must match exactly.
* Tag names cannot contain any of the characters !"#$%&'()*+,/;<=>?@ `~
, nor a space character, and cannot begin with "-", ".", or a numeric digit.
* A single root element contains all the other elements.
The definition of an XML document excludes texts that contain violations of well-formedness rules; they are simply not XML. An XML processor that encounters such a violation is required to report such errors and to cease normal processing. This policy, occasionally referred to as " draconian error handling", stands in notable contrast to the behavior of programs that process Schemas and validation
In addition to being well formed, an XML document may be ''valid''. This means that it contains a reference to a Document Type Definition (DTD), and that its elements and attributes are declared in that DTD and follow the grammatical rules for them that the DTD specifies. XML processors are classified as ''validating'' or ''non-validating'' depending on whether or not they check XML documents for validity. A processor that discovers a validity error must be able to report it, but may continue normal processing. A DTD is an example of a '' schema'' or ''grammar''. Since the initial publication of XML 1.0, there has been substantial work in the area of schema languages for XML. Such schema languages typically constrain the set of elements that may be used in a document, which attributes may be applied to them, the order in which they may appear, and the allowable parent/child relationships.Document type definition
The oldest schema language for XML is the document type definition (DTD), inherited from SGML. DTDs have the following benefits: * DTD support is ubiquitous due to its inclusion in the XML 1.0 standard. * DTDs are terse compared to element-based schema languages and consequently present more information in a single screen. * DTDs allow the declaration of standard public entity sets for publishing characters. * DTDs define a ''document type'' rather than the types used by a namespace, thus grouping all constraints for a document in a single collection. DTDs have the following limitations: * They have no explicit support for newer features of XML, most importantly namespaces. * They lack expressiveness. XML DTDs are simpler than SGML DTDs and there are certain structures that cannot be expressed with regular grammars. DTDs only support rudimentary datatypes. * They lack readability. DTD designers typically make heavy use of parameter entities (which behave essentially as textual macros), which make it easier to define complex grammars, but at the expense of clarity. * They use a syntax based on regular expression syntax, inherited from SGML, to describe the schema. Typical XML APIs such as SAX do not attempt to offer applications a structured representation of the syntax, so it is less accessible to programmers than an element-based syntax may be. Two peculiar features that distinguish DTDs from other schema types are the syntactic support for embedding a DTD within XML documents and for defining ''entities'', which are arbitrary fragments of text or markup that the XML processor inserts in the DTD itself and in the XML document wherever they are referenced, like character escapes. DTD technology is still used in many applications because of its ubiquity.Schema
A newer schema language, described by the W3C as the successor of DTDs, is XML Schema, often referred to by theRELAX NG
RELAX NG (Regular Language for XML Next Generation) was initially specified by OASIS and is now a standard (Part 2: ''Regular-grammar-based validation'' of ISO/IEC 19757 – DSDL). RELAX NG schemas may be written in either an XML based syntax or a more compact non-XML syntax; the two syntaxes are isomorphic and James Clark's conversion tool�Schematron
Schematron is a language for making assertions about the presence or absence of patterns in an XML document. It typically uses XPath expressions. Schematron is now a standard (Part 3: ''Rule-based validation'' of ISO/IEC 19757 – DSDL).DSDL and other schema languages
DSDL (Document Schema Definition Languages) is a multi-part ISO/IEC standard (ISO/IEC 19757) that brings together a comprehensive set of small schema languages, each targeted at specific problems. DSDL includes RELAX NG full and compact syntax, Schematron assertion language, and languages for defining datatypes, character repertoire constraints, renaming and entity expansion, and namespace-basedRelated specifications
A cluster of specifications closely related to XML have been developed, starting soon after the initial publication of XML 1.0. It is frequently the case that the term "XML" is used to refer to XML together with one or more of these other technologies that have come to be seen as part of the XML core. * XML namespaces enable the same document to contain XML elements and attributes taken from different vocabularies, without any naming collisions occurring. Although XML Namespaces are not part of the XML specification itself, virtually all XML software also supports XML Namespaces. * XML Base defines thexml:base
attribute, which may be used to set the base for resolution of relative URI references within the scope of a single XML element.
* XML Information Set or XML Infoset is an abstract data model for XML documents in terms of ''information items''. The infoset is commonly used in the specifications of XML languages, for convenience in describing constraints on the XML constructs those languages allow.
* XSL (Extensible Stylesheet Language) is a family of languages used to transform and render XML documents, split into three parts:
** XSLT (XSL Transformations), an XML language for transforming XML documents into other XML documents or other formats such as HTML, plain text, or XSL-FO. XSLT is very tightly coupled with XPath, which it uses to address components of the input XML document, mainly elements and attributes.
** XSL-FO (XSL Formatting Objects), an XML language for rendering XML documents, often used to generate PDFs.
** XPath (XML Path Language), a non-XML language for addressing the components (elements, attributes, and so on) of an XML document. XPath is widely used in other core-XML specifications and in programming libraries for accessing XML-encoded data.
* XQuery (XML Query) is an XML query language strongly rooted in XPath and XML Schema. It provides methods to access, manipulate and return XML, and is mainly conceived as a query language for XML databases.
* XML Signature defines syntax and processing rules for creating digital signatures on XML content.
* XML Encryption defines syntax and processing rules for encrypting XML content.
* XML model (Part 11: ''Schema Association'' of ISO/IEC 19757 – DSDL) defines a means of associating any xml document with any of the schema types mentioned above.
Some other specifications conceived as part of the "XML Core" have failed to find wide adoption, including XInclude, XLink, and XPointer.
Programming interfaces
The design goals of XML include, "It shall be easy to write programs which process XML documents." Despite this, the XML specification contains almost no information about how programmers might go about doing such processing. The XML Infoset specification provides a vocabulary to refer to the constructs within an XML document, but does not provide any guidance on how to access this information. A variety of APIs for accessing XML have been developed and used, and some have been standardized. Existing APIs for XML processing tend to fall into these categories: * Stream-oriented APIs accessible from a programming language, for example SAX and StAX. * Tree-traversal APIs accessible from a programming language, for example DOM. * XML data binding, which provides an automated translation between an XML document and programming-language objects. * Declarative transformation languages such as XSLT and XQuery. * Syntax extensions to general-purpose programming languages, for example LINQ and Scala. Stream-oriented facilities require less memory and, for certain tasks based on a linear traversal of an XML document, are faster and simpler than other alternatives. Tree-traversal and data-binding APIs typically require the use of much more memory, but are often found more convenient for use by programmers; some include declarative retrieval of document components via the use of XPath expressions. XSLT is designed for declarative description of XML document transformations, and has been widely implemented both in server-side packages and Web browsers. XQuery overlaps XSLT in its functionality, but is designed more for searching of large XML databases.Simple API for XML
Simple API for XML (SAX) is a lexical, event-driven API 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 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 functions performing the parsing, or passed down (as function parameters) into lower-level functions, or returned (as function return values) to higher-level functions. Examples of pull parsers include Data::Edit::Xml in Perl, StAX in theDocument Object Model
The Document Object Model (DOM) is an 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 beData binding
XML data binding is a technique for simplifying development of applications that need to work with XML documents. It involves mapping the XML document to a hierarchy of strongly typed objects, rather than using the generic objects created by a DOM parser. The resulting code is often easier to read and maintain, and it can help to identify problems at compile time rather than run-time. XML data binding is particularly well-suited for applications where the document structure is known and fixed at the time the application is written. By creating a strongly typed representation of the XML data, developers can take advantage of modern integrated development environments (IDEs) that provide features like auto-complete, code refactoring, and code highlighting. This can make it easier to write correct and efficient code, and reduce the risk of errors and bugs. Example data-binding systems include the Java Architecture for XML Binding (JAXB), XML Serialization in .NET Framework, and XML serialization in gSOAP.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 widely adopted. 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 typerdf:XMLLiteral
to hold wrapped, canonical XML. Facebook has produced extensions to the PHP and JavaScript languages that add XML to the core syntax in a similar fashion to E4X, namely XHP and JSX respectively.
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<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 communicated primarily through 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. The SGML declaration was removed; thus, XML has a fixed delimiter set and adoptsVersions
1.0 and 1.1
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 particular 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 the2.0
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 skunkworks), which one of the original developers of XML has written, contains some proposals for what an XML 2.0 might look like, including elimination of DTDs from syntax, as well as integration of XML namespaces, XML Base and XML Information Set into the base standard.MicroXML
In 2012, James Clark (technical lead of the XML Working Group) and John Cowan (editor of the XML 1.1 specification) formed the MicroXML Community Group within the W3C and published MicroXML, a specification for a significantly reduced subset of XML. MicroXML provides a much simpler core syntax by stripping away many features of full XML, such as document type declarations and CDATA sections, while ensuring XML namespace validity by disallowing names conflicting with namespace prefixing.Binary XML
Due to the verbosity of textual XML, various binary formats have been proposed as compact representations for XML: Fast Infoset, based on ASN.1, was published as an international standard by the ITU-T in 2005, and later byCriticism
XML and its extensions have regularly been criticized for verbosity, complexity and redundancy. 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. However, XML data binding systems allow applications to access XML data directly from objects representing aSee also
* AIDX * Binary XML * Comparison of data-serialization formats * EBML * Extensible programming * List of XML markup languages * List of types of XML schemas * Simple XML * WBXML * XML ProtocolNotes
References
Citations
Bibliography
* * * *Further reading
* Annex A of ISO 8879:1986 (SGML) * * * * * *External links
* , World Wide Web Consortium (W3C)