How to write a simple XML document

This is very simple example, but this XML document contains all the important parts that you will find in all XML documents.

<?xml version="1.0"?>
<home.page>
   <head>
      <title>
	 Author COde	
      </title>
   </head>
   <body>
      <main.title>
	 Welcome to Author COde	
      </main.title>
      <rule/>
      <text>
	<para>
           Hello Guest, welcome to author code
	</para>
      </text>	
   </body>
 <footer source="\image\footer.bmp">
</home.page>

You can type above code in notepad and save this document with .xml extension. Now you can open this document in any web browser.

you can see this document in browser like this:

Description

The XML Declaration

The XML declaration (see first line )

The Root Element

Each XML document must have one root element and all the other elements must be completely enclosed in that element ( see the and ). Basically in XML an element normally consists of three things : a start tag, content and an end tag.

An Empty Element

Empty elements are special case in XML. In SGML and HTML, it is obvious from DTD (Document type Definitions) definition of an empty element that it is empty and has no comment, To do so there is a special empty tag close delimiter( see tag)

Attributes

Element tags can include one or more optional or mandatory attributes that give further information about elements they delimit. Attributes can only be specified in the element start tag like this:

 <ElementName AttributeName="AttributeValue">

Basic rules for a well formed XML document

An XML(Extensible markup Language) is a meta-markup language that provides a format for describing structured data. It is necessary that an XML document must have the following conditions:

  • An XML document must have only one root element.
  • An XML document must have a start and end tag for every element.
  • Start tag and end tag must match tags in XML document.
  • Values of attributes must always in quotes.
  • If XML document has parameters entities than it is necessary that they must be declared before used.
  • Same start tag should not have one attribute more than once.
  • Non empty tags must be properly nested etc.