XML Syntax

Here simple syntax rules to write in XML document.
<?xml version="1.0" encoding=?ISO-8859-1??>  
<body>Don't forget Mother birthday this weekend! </body>  
  • The first line syntax is the XML declaration. It defines the xml version and encoding used in the document.
<?xml version="1.0" encoding="ISO-8859-1?">
  • Next line describes the root element of document.
  • Next 4 lines describes the child element of the root elements.
<to>Ajay</to> <from>Arun</from> <heading>Reminder</heading> <body>Don't forget Abhay birthday this weekend! </body>
  • Last lines describes the end of the root element.
</note> It is case sensitive and begin with "<?xml>" where xml is written in lower case.

Example of XML: Movie

File: movie.xml
<movie category="ACTION">    
            <title lang="en">Force</title>    
            <director>Nishikant Kamat</director>    
            <budget>120 million</budget>    
    <movie category="ROMANTIC">    
            <title lang="en">DDLJ</title>    
            <director>Yash chopra</director>    
            <budget>40 million</budget>    
    <movie category="COMEDY">    
<title lang="en">golmaal</title>    
<director>Rohit sheety</director>    
The root element in the example is <Movies-store>. All elements in the document are contained within <Movies-store>. The <Movie> element has 4 children: <title>, < director>, <year> and <budget>.

Example of Email

File: email.xml
<?xml version="1.0" encoding="UTF-8"?>    
        <body>Hello brother, Good morning!</body>    
        <heading>New year wish</heading>    
        <body>Happy New Year Abhay</body>    
<heading>Morning walk</heading>    
<body>Please start morning walk to stay fit!</body>    
<heading>Health Tips</heading>    
<body>Smoking is injurious to health!</body>