Extensible Markup Language, or XML, is a simplified version of SGML. It is currently receiving a lot of attention. XML is essentially a markup language, meaning that it uses symbols to describe its own content. It also enables you to identify and organize your information in a more accurate and flexible way. This article is the first in a four-part series that introduces you to using XML with Delphi and the DOM.
It is worth know a few details about this language before we discuss how to use it in Delphi:
You can add comments within <!—andmarkers, which are basically ignored by XML processors. There are also directives and processing instructions, enclosed within <? and ?> markers.
White spaces are generally ignored. While human beings must be able to read your XML tags, your applications won't care much about them.
There are a few reserved characters that you cannot use in the text. The only three characters you can never use are the less-than character (or the left angle bracket, <, used to delimit a marker), which is replaced by <, the greater-than character, which is replaced by >, and the ampersand character (&), which is replaced by &. Other optional special characters are ' for the single quote(‘), and " for the double quote(").
To add non XML content (for example, binary information or a script), you can use a CDATA section, enclosed within <![CDATA [and]]>.
All markers are enclosed by angle brackets, < and >. Markers (or tags) are case sensitive.
For each opening marker there must be a matching closing marker denoted by a initial slash character: <node>value</node>
Markers must not overlap; they must be properly nested.
If a marker has no content (but is needed), you can replace the opening and closing markers with a single marker that includes a trailing slash:<node/>
Markers can have attributes, using multiple embedded tags and only one block of text representing the value of the node. XML nodes can have either a textual value or embedded tags, but not both.
A node can have multiple child nodes with the same tag; tags do not have to be unique. Attributes, however, have to be unique for each node.
It is worth adding that an XML document needs to be well-formed if it is to be used in web browsers or other applications. There are a few extra rules that need to be followed for XML documents to be consideredsyntactically correct. So let’s look at what is meant by syntactically correct:
Each XML document must indicate that it is an XML document, which version of XML it complies with, and finally, what type of character encoding it takes:
<?xml version="1.0" encoding="iso-8859-1"?>
Encodings can include Unicode character sets such as UTF-8, UTF-16 and UTF-32 and also some ISO encodings such as ISO-1064-xxx or ISO-8859-xxx. The prologue can also include external declarations, the schema used to validate the document, namespace declaration and associated XSL file, and some internal entity declarations.
A well-formed XML document will have no problems being loaded into a web browser or any other XML-compliant application.