Introduction
XML is a text format for documents and data made of nested, named elements. The W3C published XML 1.0 in 1998 as a simpler form of SGML. XML itself only sets the syntax; each use defines its own elements, often with a schema that a validator can check.
Many other formats are XML underneath, including
SVG images, GPX
tracks, RSS feeds and the parts inside a Word
document. A file saved with the plain .xml extension is usually data or
settings for a particular program.
Structure
An XML file may open with a declaration giving the version and character encoding,
<?xml version="1.0" encoding="UTF-8"?>. Without one the encoding is
UTF-8, or UTF-16 when the file starts with a byte order mark.
The content is a single root element. An element is a start tag and an end tag around
its content, <name>…</name>, or one empty tag,
<name/>. Start tags carry attributes as
key="value" pairs. Elements nest strictly, with no overlap. Text may use
entity references such as & and <, and may
include comments, processing instructions and CDATA sections. Namespaces let one file
mix the elements of several vocabularies.
A file that breaks XML’s well-formedness rules is not XML at all: a parser must stop and report it. A document type definition can declare the structure, attributes and entities a document uses. There are two versions, XML 1.0 and XML 1.1.
The other pages cover the syntax, DTDs, entities, namespaces, the well-formedness and validity constraints, and encodings and media types.
0Declaration version and encoding (optional)text…Document type or comments (optional)text…Root element every other element nests inside ittext
Not described
The pages follow XML 1.0 and 1.1 and the namespaces recommendation. The explorer reads XML with every well-formedness constraint, namespaces and validity against a complete internal DTD.
Known, not yet covered
- Viewer: external DTDs are not fetched, so validity is checked only when the internal subset is complete.
- Viewer: validity constraints on parameter-entity nesting, content-model determinism and XML 1.1 normalisation are not checked.
- Viewer: a file over 48 MiB (or a decoded entry over 8 MiB) is read in windows. It is checked for well-formedness, names against the Name production, namespaces and invalid UTF-8, and entity references are checked; validity against a DTD, what a DTD declares beyond its entities and entity expansion are checked only in a file held whole. A file with more problems than the whole-file reader keeps (4 Mi) is read in windows too.
- Viewer: in windows, the text, comments, CDATA sections and instructions between elements are one node each, shown in groups of 1,000; the Text tab is shown in windows of 1 MiB with First, Previous, Next, Last and Go to line, so every byte is reachable. The problems past the first 2,000,000 of a file read in windows are listed by a second pass over the file, in pages.
- Viewer: only the EBCDIC code pages 037 and 500 are decoded.
- Viewer: files with the extensions
.dtd,.entand.modreach the XML plugin only through Identify, because the registry has no rows for them.
Also used for
- xCal: iCalendar in XML – iCalendar as XML: events, to-dos and time zones as elements.
- xCard: vCard in XML – vCard 4.0 contacts as XML: names, numbers and addresses as elements.
Links
Software
- Visual Studio Code – free code editor with XML highlighting and extensions for validation (Windows, macOS, Linux)
- Notepad++ – free text editor with XML highlighting (Windows)
- Oxygen XML Editor – professional XML editor with schema validation and XSLT (Windows, macOS, Linux)
- Firefox – web browser that shows XML as a tree, as other browsers do (Windows, macOS, Linux)
- Microsoft Excel – spreadsheet that can import XML data as a table (Windows, macOS)
Developers
- libxml2 – XML parser with the
xmllintcommand-line tool (C) - lxml – fast XML and HTML processing built on libxml2 (Python)
- xml.etree.ElementTree – Python’s built-in XML module (Python)
- Expat – small streaming XML parser (C)
Reference
- Extensible Markup Language (XML) 1.0 – the W3C Recommendation
- Extensible Markup Language (XML) 1.1 – the W3C Recommendation for XML 1.1
- Namespaces in XML 1.0 – the W3C Recommendation for namespaces
- Namespaces in XML 1.1 – namespaces for XML 1.1, including IRIs