Creating XML document

The very first line of an XML document should be of the form:

<?xml version="version" encoding="encoding" standalone="yes/no" ?>

Each of the attributes of the declaration is optional, as well as the declaration itself, but it is a good practice to include all this information.

version
The most recent released version of XML is 1.1, whereas the most used one is 1.0. The difference is minor and is outside of scope of this course.
encoding
This attribute specifies the document character set. Its default value is "UTF-8". We will use encoding "ISO-8859-1". See here for more information on character encodings.
standalone
The default value of this attribute is "no". It tells the processor whether this document contains all necessary information within itself or relies on external DTD scheme. The value "yes" means that everything needed to process this document is in the document itself. In this case all external references to DTD will be ignored. The value "no" means that the document can reference external files.

Example of an XML document:

<?xml version="1.0"?>
<job-posting>
    <title>
    Job Title: Webmaster
    </title>

    <description>
    We are looking for a Webmaster to oversee the management of
    our company website. The Webmaster will be responsible for working
    with other staff members to collect information for the Website, and
    for creating and maintaining the Web pages.
    </description>

    <skills>
    Expected skills:
    <skill>Basic writing skills</skill>
    <skill>Good communication skills</skill>
    <skill>HTML</skill>
    </skills>
</job-posting>

Show the result

Well-formed XML documents

The XML documents should be well-formed, as specified below. A non well-formed document will generate an error in a parse program.

  1. An XML document must contain one and only one root element.
  2. All elements have to have an opening tag and a closing one. Note that the element names are case-sensitive. They can start with a letter or an underscore (_) and can contain only letters (a-z, A-Z), numbers (0-9), hyphens (-), periods (.), and underscores (_). The names cannot start with "xml".
  3. All elements must be nested properly.
  4. All attributes must have a value and it must be enclosed in quotes. Attributes must be placed in the opening tag and no attribute has to appear twice.
  5. Certain markup characters cannot appear in the context of any elements. Examples include the '<' and '>' characters.