XML Primer

From MircWiki
Revision as of 21:39, 30 June 2006 by Johnperry (talk | contribs)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

MIRC uses extensible markup language (XML) to encode configuration data, indexed information, and MIRCdocuments themselves. To use MIRC, an understanding of XML is not necessary, but administrators may find it helpful. To assist readers who are new to XML, the following description will provide enough background to read and understand the XML in the MIRC documentation.

An XML document is typically a text file, although it can also be a text stream obtained from a server via a network. Content in an XML document is contained in XML elements. An XML element is identified by a name enclosed in < > brackets. For example, an element called MIRCdocument is coded as <MIRCdocument>. The notation <elementname> is called a tag. Every element tag must be paired with a tag that defines its end. The end tag for <MIRCdocument> is coded as </MIRCdocument>. The value of an element is the content between the element tag and its end tag.

An element may contain attributes. An attribute is coded within the element tag itself. An attribute consists of a name, an equals sign, and an attribute value. The attribute value is enclosed in quotes. The following is an example of an element with an attribute:

<MIRCdocument docref="http://www.somewhere.edu/mydocument.xml">
	This text is the value of the element.

An element may be empty, meaning that it has no element value (although it may have attributes). Such an element is usually coded as:

<element attribute="attribute value"/>

(note the slash before the >), although the form:

<element attribute="attribute value"></element>

is equally acceptable.

When XML documents are processed, whitespace is often insignificant. For example, multiple elements and their contents may appear on one line, and multiple spaces, tabs, and newline characters are sometimes reduced to a single space.

The value of an element may contain other elements, thus allowing the nesting of elements in an XML document. A well-formed XML document must have exactly one top-level, or root, element, within which all other content is contained, and every element must be paired with its end tag within the value of which it is a part. For example, the following is well-formed:

	<p>This is a paragraph.</p>
	<p>This is another paragraph.</p>

The following is not well-formed, and is rejected by XML parsers:

	This text is one paragraph.
	This is another paragraph.

The last example is a common sloppy use of HTML. When including HTML within XML elements, it is imperative to provide an end tag for each HTML element.

The following document is also not well-formed:

	<element1> …
		<element2> …

because <element2>, which is within <element1>, is not closed within the value of <element1>.

Whenever an XML file is edited, it is imperative that it remain well-formed. An easy way to check that a document is well-formed is to open it in a web browser that parses XML documents. One such browser is Microsoft's Internet Explorer.