The ('''XML''') is a . It is a simplified subset of Standard Generalized Markup Language ( SGML ). Its primary purpose is to facilitate the sharing of data across different systems, particularly systems connected via the Internet . Languages based on XML (for example, Geography Markup Language (GML), RDF/XML , RSS , MathML , XHTML , SVG , and MusicXML ) are defined in a formal way, allowing programs to modify and validate documents in these languages without prior knowledge of their form.
|   |
A conversation with Tim Bray: Searching for ways to tame the world’s vast stores of informationurl=http://wwwacmqueuecom/modulesphpname=Content&pa=showpage&pid=282
|
|   |
Timlast=Brayyear=February 2005publisher=Association for Computing Machinery's "Queue site"
|
|   |
April 16 accessyear=2006
|
|
|
|   |
Interactive multimediachapter=Publishers, multimedia, and interactivity
|
|   |
Cobb Groupid=ISBN: 1556151241year=1988
|
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. He received support in his efforts from
Microsoft .
XML was designed by an eleven-member
Working Group , supported by an (approximately) 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.
James Clark served as Technical Lead of the Working Group, notably contributing the empty-element "
" 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 twenty weeks of intense work between July and November of 1996. Further design work continued through
1997 , and XML 1.0 became a W3C Recommendation on
February 10 ,
1998 .
XML 1.0 achieved the Working Group's goals of Internet usability, general-purpose usability, SGML compatibility, facilitation of easy development of processing software, minimization of optional features, legibility, formality, conciseness, and ease of authoring.
Clarifications and minor changes were accumulated in published errata and then incorporated into a Second Edition of the XML 1.0 Recommendation on
October 6 ,
2000 . Subsequent errata were incorporated into a Third Edition on
February 4 ,
2004 .
Also published on the same day as XML 1.0 Third Edition was XML 1.1, a variant of XML that encourages more consistency in how characters are represented and relaxes restrictions on names, allowable characters, and end-of-line representations.
Both XML 1.0 Third Edition and XML 1.1 are considered current versions of XML.
XML provides a text-based means to describe and apply a tree-based structure to information. At its base level, all information manifests as text, interspersed with
Markup that indicates the information's separation into a hierarchy of ''character data'', container-like ''elements'', and ''attributes'' of those elements. In this respect, it is similar to the
LISP programming language's
S-expression s, which describe tree structures wherein each node may have its own property list.
The fundamental unit in XML is the ''
Character '', as defined by the
Universal Character Set . Characters are combined in certain allowable combinations to form an XML ''document''. The document consists of one or more ''entities'', each of which is typically some portion of the document's characters,
Encoded as a series of
Bit s and stored in a
Text File .
The ubiquity of text file authoring software (
Word Processor s) facilitates rapid XML document authoring and maintenance, whereas prior to the advent of XML, there were very few data description languages that were general-purpose, Internet protocol-friendly, and very easy to learn and author. In fact, most data interchange formats were proprietary, special-purpose, "binary" formats (based foremost on bit sequences rather than characters) that could not be easily shared by different software applications or across different computing platforms, much less authored and maintained in common text editors.
By leaving the names, allowable hierarchy, and meanings of the elements and attributes open and definable by a customizable ''
Schema '', XML provides a syntactic foundation for the creation of custom, XML-based markup languages. The general syntax of such languages is rigid — documents must adhere to the general rules of XML, assuring that all XML-aware software can at least read (''parse'') and understand the relative arrangement of information within them. The schema merely supplements the syntax rules with a set of constraints. Schemas typically restrict element and attribute names and their allowable containment hierarchies, such as only allowing an element named 'birthday' to contain 1 element named 'month' and 1 element named 'day', each of which has to contain only character data. The constraints in a schema may also include
Data Type assignments that affect how information is processed; for example, the 'month' element's character data may be defined as being a month according to a particular schema language's conventions, perhaps meaning that it must not only be formatted a certain way, but also must not be processed as if it were some other type of data.
In this way, XML contrasts with HTML, which has an inflexible, single-purpose vocabulary of elements and attributes that, in general, cannot be repurposed. With XML, it is much easier to write software that accesses the document's information, since the data structures are expressed in a formal, relatively simple way.
XML makes no prohibitions on how it is used. Although XML is fundamentally text-based, software quickly emerged to
Abstract it into other, richer formats, largely through the use of datatype-oriented schemas and
Object-oriented Programming paradigms (in which the document is manipulated as an object). Such software might only treat XML as serialized text when it needs to transmit data over a network, and some software doesn't even do that much. Such uses have led to "binary XML", the relaxed restrictions of XML 1.1, and other proposals that run counter to XML's original spirit and thus garner an amount of criticism.
Some features of XML that make it well-suited for data transfer are:
XML is also heavily used as a format for
Document Storage and processing, both online and offline, and offers several benefits:
- its robust, logically-verifiable format is based on International Standards ;
- the Hierarchical structure is suitable for most (but not all) types of documents;
- it manifests as Plain Text files, unencumbered by licenses or restrictions;
- it is platform-independent, thus relatively immune to changes in technology;
- it and its predecessor, SGML , have been in use since 1986 , so there is extensive experience and software available.
For certain applications, XML also has the following weaknesses:
- Its syntax is fairly verbose and partially redundant. This can hurt human readability and application efficiency, and yields higher storage costs. It can also make XML difficult to apply in cases where Bandwidth is limited, though Compression can reduce the problem in some cases. This is particularly true for multimedia applications running on cell phones and PDAs which want to use XML to describe images and video.
- Parsers should be designed to recurse arbitrarily nested data structures and must perform additional checks to detect improperly formatted or differently ordered syntax or data (this is because the markup is descriptive and partially redundant, as noted above). This causes a significant overhead for most basic uses of XML, particularly where resources may be scarce - for example in Embedded Systems . Furthermore, additional security considerations arise when XML input is fed from untrustworthy sources, and resource exhaustion or stack overflows are possible.
- Some consider the syntax to contain a number of obscure, unnecessary features born of its legacy of SGML compatibility. However, an effort to settle on a subset called "Minimal XML" led to the discovery that there was no consensus on ''which'' features were in fact obscure or unnecessary.
- The basic parsing requirements do not support a very wide array of Data Type s, so interpretation sometimes involves additional work in order to process the desired data from a document. For example, there is no provision in XML for mandating that "3.14159" is a floating-point number rather than a seven-character string. XML Schema Languages add this functionality.
- Modelling overlapping (non-hierarchical) data structures requires extra effort.
- Mapping XML to the relational or Object Oriented Paradigm s is often cumbersome.
- Some have argued that XML can be used for data storage only if the file is of low volume, but this is only true given particular assumptions about architecture, data, implementation, and other issues.
:See also:
"XML Sucks" on c2.com
The basic syntax for one element in XML is
content
Here is an example of a simple recipe expressed using XML:
Basic bread
Flour
Yeast
Water
Salt
Mix all ingredients together, and knead thoroughly.
Cover with a cloth, and leave for one hour in warm room.
Knead again, place in a tin, and then bake in the oven.
The first line is the : it is an optional line stating what version of XML is in use (normally version 1.0), and may also contain information about character encoding and external dependencies.
The remainder of this document consists of nested ''element''s, some of which have ''attribute''s and ''content''. An typically consists of two tags, a ''start tag'' and an ''end tag'', possibly surrounding text and other elements. The '''start tag''' consists of a name surrounded by angle brackets, like "
<step>"; the '''end tag''' consists of the same name surrounded by angle brackets, but with a forward slash preceding the name, like "
</step>". The element's '''content''' is everything that appears between the start tag and the end tag, including text and other (child) elements. The following is a complete XML element, with start tag, text content, and end tag:
Knead again, place in a tin, and then bake in the oven.
In addition to content, an element can contain — name-value pairs included in the start tag after the element name. Attribute values must always be quoted, using single or double quotes, and each attribute name should appear only once in any element.
Flour
In this example, the ''ingredient'' element has two attributes: ''amount'', having value "3", and ''unit,'' having value "cups". In both cases, at the markup level, the names and values of the attributes, just like the names and content of the elements, are just textual data — the "3" and "cups" are not a quantity and unit of measure, respectively, but rather are just character sequences that the document author may be using to ''represent'' those things.
In addition to text, elements may contain other elements:
Mix all ingredients together, and knead thoroughly.
Cover with a cloth, and leave for one hour in warm room.
Knead again, place in a tin, and then bake in the oven.
In this case, the ''instructions'' element contains three ''step'' elements. XML requires that elements be properly nested — elements may never overlap. For example, this is not well-formed XML, because the ''em'' and ''strong'' elements overlap:
<!-- WRONG! NOT WELL-FORMED XML! -->
<p>Normal <em>emphasized <strong>strong emphasized</em> strong</strong></p>
Every XML document must have exactly one top-level (alternatively called a ''document element''), so the following would also be a malformed XML document:
<?xml version="1.0" encoding="UTF-8"?>
<!-- WRONG! NOT WELL-FORMED XML! -->
<thing>Thing one</thing>
<thing>Thing two</thing>
XML provides special syntax for representing an element with empty content. Instead of writing a start tag followed immediately by an end tag, a document may contain the where a slash ''follows'' the element name. The following two examples are functionally equivalent:
<foo></foo>
<foo />
XML provides two methods for escaping (or simply representing) special characters: ''entity references'' and ''
Numeric Character Reference s''.
An in XML is a named body of data, usually text, such as an unusual character.
An is a placeholder that represents that entity. It consists of the entity's name preceded by an
Ampersand ("
&") and followed by a
Semicolon ("
;"). XML has five predeclared entities:
- & (&)
- < (<)
- > (>)
- ' (')
- " (")
Here is an example using a predeclared XML entity to represent the ampersand in the name "AT&T":
<company-name>AT&T</company-name>
If more entities need to be declared, this is done in the document's
DTD . A basic example of doing so in a minimal internal DTD follows. Declared entities can describe single characters or pieces of text, and can reference each other.
]>
©right-notice;
When viewed in a suitable browser, such as
Firefox , the XML document above appears as:
Copyright © 2006, XYZ Enterprises
look like entities, but instead of a name, they contain the "
# " character followed by a number. The number (in decimal or "
x"-prefixed
Hexadecimal ) represents a Unicode code point, and is typically used to represent characters that are not easily encodable, such as an Arabic character in a document produced on a European computer. The ampersand in the "AT&T" example could also be escaped like this (decimal 38 and hexadecimal 26 both represent the Unicode value for the "&" character):
<company-name>AT&T</company-name>
<company-name>AT&T</company-name>
There are many more rules necessary to be sure of writing well-formed XML documents, such as the exact characters allowed in an XML name, but this quick tour provides the basics necessary to read and understand many XML documents.
For an XML document to be correct, it must be:
- . A well-formed document conforms to all of XML's syntax rules. For example, if a non-empty element has an opening tag with no closing tag, it is not ''well-formed''. A document that is not well-formed is not considered to be XML; a parser is required to refuse to process it.
- . A valid document has data that conforms to a particular set of user-defined content rules, or XML Schema s, that describe correct data values and locations. For example, if an element in a document is required to contain text that can be interpreted as being an Integer numeric value, and it instead has the text "hello", is empty, or has other elements in its content, then the document is not ''valid''.
An XML document is text, which is a sequence of characters. The specification support for
Unicode encodings
UTF-8 and
UTF-16 (
UTF-32 is not mandatory). The use of other non-Unicode based encodings, such as
ISO-8859 , is admitted and is indeed widely used and supported.
A well-formed document must conform to the following rules, among others:
- One and only one Root Element exists for the document. However, the XML declaration, processing instructions, and comments can precede the root element.
- Non-empty elements are delimited by both a start-tag and an end-tag.
- Empty elements may be marked with an empty-element (self-closing) tag, such as
<IAmEmpty />. This is equal to <IAmEmpty></IAmEmpty>.
- All attribute values are quoted, either single (') or double (") quotes. Single quotes close a single quote and double quotes close a double quote.
- Tags may be nested but must not overlap. Each non-root element must be completely contained in another element.
- The document complies to its character set definition. The charset is usually defined in the xml declaration but it can be provided by the transport Protocol , such as HTTP . If no charset is defined, usage of a Unicode encoding is assumed, defined by the Unicode Byte Order Mark . If the mark does not exist, UTF-8 is the default.
Element names are case-sensitive. For example, the following is a well-formed matching pair
:
<Step> ...
</Step>
whereas this is not
:
<Step> ...
</step>
The careful choice of names for XML elements will convey the
Meaning of the
Data in the
Markup . This increases human readability while retaining the rigor needed for software parsing.
Choosing meaningful names implies the semantics of elements and attributes to a human reader without reference to external documentation. However, this can lead to verbosity, which complicates authoring and increases file size.
An XML document that complies with a particular
Schema , in addition to being well-formed, is said to be .
An
XML Schema is a description of a type of XML document, typically expressed in terms of constraints on the structure and content of documents of that type, above and beyond the basic constraints imposed by XML itself. A number of standard and proprietary XML schema languages have emerged for the purpose of formally expressing such schemas, and some of these languages are XML-based, themselves.
Before the advent of generalised data description languages such as SGML and XML, software designers had to define special
File Format s or small languages to share data between programs. This required writing detailed specifications and special-purpose parsers and writers.
XML's regular structure and strict parsing rules allow software designers to leave parsing to standard tools, and since XML provides a general,
Data Model -oriented framework for the development of application-specific languages, software designers need only concentrate on the development of rules for their data, at relatively high levels of abstraction.
Well-tested tools exist to validate an XML document "against" a schema: the tool automatically verifies whether the document conforms to constraints expressed in the schema. Some of these validation tools are included in XML parsers, and some are packaged separately.
Other usages of schemas exist: XML editors, for instance, can use schemas to support the editing process.
The oldest schema format for XML is the
Document Type Definition (DTD), inherited from SGML. While DTD support is ubiquitous due to its inclusion in the XML 1.0 standard, it is seen as limited for the following reasons:
- It has no support for newer features of XML, most importantly namespaces.
- It lacks expressivity. Certain formal aspects of an XML document cannot be captured in a DTD.
- It uses a custom non-XML syntax, inherited from SGML, to describe the schema.
A newer XML schema language, described by the W3C as the successor of DTDs, is
XML Schema , or more informally referred to in terms of the
Initialism for XML Schema instances, XSD (
XML Schema Definition ). XSDs are far more powerful than DTDs in describing XML languages. They use a rich
Datatyping system, allow for more detailed constraints on an XML document's logical structure, and are required to be processed in a more robust validation framework. Additionally, XSDs use an XML based format, which makes it possible to use ordinary XML tools to help process them, although WXS (W3C XML Schema) implementations require much more than just the ability to read XML.
Criticisms of WXS include the following:
- The specification is very large, which makes it difficult to understand and implement.
- The XML-based syntax leads to verbosity in schema description, which makes XSDs harder to read and write.
Another popular schema language for XML is 's
Trang conversion tool , the advantage of using standard XML tools is not lost. Compared to XML Schema, RELAX NG has a simpler definition and validation framework, making it easier to use and implement. It also has the ability to use any datatype framework on a plug-in basis; for example, a RELAX NG schema author can require values in an XML document to conform to definitions in XML Schema Datatypes.
Some schema languages not only describe the structure of a particular XML format but also offer limited facilities to influence processing of individual XML files that conform to this format. DTDs and XSDs both have this ability; they can for instance provide attribute defaults. RELAX NG intentionally does not provide these facilities.
XML fully supports
Unicode character encodings in element names, attributes and data. Therefore the following is a perfectly well-formed XML document, even though it includes both Chinese and Russian characters:
<?xml version="1.0" encoding="UTF-8"?>
<俄语>Данные</俄语>
Extensible Stylesheet Language (XSL) is a supporting technology that describes how to format or transform the data in an XML document. The document is changed to a format suitable for browser display. The process is similar to applying a
CSS to an
HTML document for rendering.
Without using CSS or XSL, a generic XML document is rendered as raw XML text by most
Web Browser s. Browsers like
Internet Explorer ,
Firefox , and
Opera display it with 'handles' that allow parts of the structure to be expanded or collapsed with mouse-clicks.
In order to style the rendering in a browser with CSS, the XML document must include a special reference to the stylesheet:
:
<?xml-stylesheet type="text/css" href="myStyleSheet.css"?>
See the CSS article
For An Example Of This In Action .
This is different from specifying a stylesheet in HTML, which uses the
<link> element.
To specify a client-side
XSL Transformation (XSLT), the following processing instruction is required in the XML:
:
<?xml-stylesheet type="text/xsl" href="transform.xsl"?>
Client-side XSLT is not supported by
Opera 8.5, however their 9.0 (beta) does support it.
The alternative is conversion of XML into HTML, PDF and other formats ''on the server''. Many
Such Processors exist, and the end-user then need not be aware of what has been going on 'behind the scenes'.
See the XSLT article
For An Example Of Server-side XSLT In Action .
- makes it is possible to refer to individual parts of an XML document. This provides random access to XML data for other technologies, including XSLT, XSL-FO, XQuery etc. XPath expressions can refer to all or part of the text, data and values in XML elements, attributes, processing instructions, comments etc. They can also access the names of elements and attributes. XPaths can be used in both valid and well-formed XML, with and without defined namespaces.
- is to XML what SQL is to relational databases.
- enable the same document to contain XML elements and attributes taken from different vocabularies, without any Naming Collision s occurring.
- defines the syntax and processing rules for creating Digital Signatures on XML content.
- defines the syntax and processing rules for Encrypting XML content.
- is a system for addressing components of XML-based internet media.
SAX and
DOM are
API s widely used to process XML data. SAX is used for serial processing whereas DOM is used for random-access processing. Another form of XML Processing API is data binding, where XML data is made available as a strongly typed programming language data structure, in contrast to the DOM. Example data binding systems are the Java Architecture for XML Binding (JAXB)
and the Strathclyde Novel Architecture for Querying XML (SNAQue) [http://www.cis.strath.ac.uk/research/snaque/ .
A filter in the
Extensible Stylesheet Language (XSL) family can transform an XML file for displaying or printing.
- is a declarative, XML-based page layout language. An XSL-FO processor can be used to convert an XSL-FO document into another non-XML format, such as PDF .
- is a declarative, XML-based document transformation language. An XSLT processor can use an XSLT ''stylesheet'' as a guide for the conversion of the data tree represented by one XML document into another tree that can then be serialized as XML, HTML, plain text, or any other format supported by the processor.
- is a W3C language for querying, constructing and transforming XML data.
- is a path expression language for selecting data within XML documents. XSL-FO, XSLT and XQuery all make use of XPaths.
The native file format of
OpenOffice.org ,
AbiWord , and
Apple 's
IWork applications is XML. Some parts of
Microsoft Office 11 will also be able to edit XML files with a user-supplied schema (but not a DTD), and on
June 2 ,
2005 Microsoft announced that, by late 2006 all the files created by users of its Office suite of software will be formatted with web-centered XML specifications. There are dozens of other
XML Editor s available.
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 third edition, as published on
February 4 ,
2004 . It is widely implemented and still recommended for general use. The second, ''XML 1.1'', was initially published on the same day as XML 1.0 Third Edition. It contains features — some contentious — that are intended to make XML easier to use for certain classes of users (mainframe programmers, mainly). XML 1.1 is not very widely implemented and is recommended for use only by those who need its unique features.
XML 1.0 and XML 1.1 differ in the requirements of characters used for element and attribute names: XML 1.0 only allows characters which are defined in
Unicode 2.0, which includes most world scripts, but excludes those which were added in later Unicode versions. Among the excluded scripts are
Mongolian ,
Cambodian ,
Amharic ,
Burmese , and others.
XML 1.1 allows the use of more
Control Character s than XML 1.0. In fact, almost any Unicode character can be used in the character data and attribute values of an XML 1.1 document, even if the character is not defined, aside from having a code point, in the current version of Unicode.
Other minor changes between XML 1.0 and XML 1.1 are that
Control Character s are now allowed to be included but only when escaped, and two special Unicode line break characters are included and must be treated as whitespace.
XML 1.0 documents are also well-formed XML 1.1 documents, with one exception: XML documents that contain unescaped
C1 control characters are now malformed: this is because XML 1.1 requires the C1 control characters to be escaped with numeric character references.
There are also discussions on an XML 2.0, although it remains to be seen if such will ever come about. XML-SW (SW for s,
XML Base and
XML Information Set (''infoset'') into the base standard.