XML Document

In this lesson we’ll demonstrate you to create a well formed XML Document, it is very easy to create XML Document as there is predefined specification for creating XML Document –

Let’s take a look at the example below that demonstrate the standard structure for XML Document:

An XML Document mainly consist of two parts that is prolog and body.

XML Prolog

This is first and most important part of an XML Document. It tells the browser that this document is marked up in XML.The prolog contains an XML declaration, possibly followed by a document type declaration (DTD).

XML Declaration

When we look at the XML Document we notice first line as below –

It is used as the XML declaration it tell the browser that the document is written in XML and specifies which version of XML. It also specify the language of character encoding.

Although XML declaration is not necessary but it is best practice to include it in your XML documents.

Document Type Definition (DTD)

Document Type Declaration is used to specify the set of rules for current XML Document structure as per the requirement. Set of rules or instructions can be defined in a separate file and this file can be used to validate XML document in which it is included and application stops to process the XML Document further if the document doesn’t adhere to the DTD.

Example

XML Comments

XML comments begin with <!-- and ends with -->. Like any other programming language XML Comments is used to add annotations or remarks to enhance the readability of the XML Code for the programmers. Comments can be placed anywhere in an XML document.

Example

XML Body

The body of XML Document is consists of a container element know as root element and other elements placed inside the root element.

Example