Category Archives: xml

XML Element

The XML Element is combination of opening-tag, data and closing-tag . The data may be plain text or child elements, or a combination of text and child elements. An XML Document is consist of a tree of XML Elements with a single root element as shown below.

Syntax:

Example:

 

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

 

 

XML Syntax

Here is quick list of syntax rules that must be followed while creating an XML Document.

XML Documents Must Have a Root Element

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

In the below example <inbox>…</inbox> is acting as root element.

XML Elements Must Have a Closing Tag

All XML element must be ended using a closing tag. It is illegal to remove closing tag.

XML Tags are Case Sensitive

XML tags are case sensitive. The tag <Message> is different from the tag <message>.

Start and End tags must be written in the same case.

XML Elements Must be Properly Nested

All XML elements must be properly nested within each other. As child element should be closed before parent element.

XML Attribute Values Must be Quoted

Like HTML elements XML elements can have attributes in name/value pairs, and this attribute values must always be quoted properly.

XML Introduction

The acronym XML stands for eXtensible Markup Language, the essence of XML is in its name:

Extensible: We can define our own custom tags based on type of information we want to store.
Markup : It uses the Markup Tags or elements.
Language: XML programming language like HTML , used to represent information in a structured manner.

XML is created by World Wide Web Consortium (W3C) in late 90’s with the sole purpose to represent, store and exchange information in structured and self describing manner.XML is a simple form of (or subset) of the Standard Generalized Markup Language (SGML) developed in 1970s for the large-scale storage of structured text documents.

XML is internationally recognized standard format for cross platform (Hardware and Software independent) information exchange.

XML Features:

  • Excellent with the handling of structural information.
  • Emphasis on descriptive rather than procedural markup.
  • Text data description.
  • Hardware and Software independent.
  • Handles data in a tree structure with one-root element.
  • Excellent for long-term data storage and data re usability.
  • It supports a wide variety of applications.
  • It is easy to learn XML and to create XML Document.

XML Uses:

  • XML Document can be used to store configuration information.
  • XML Document can be used to store structural data or information.
  • XML Documents can be used to transmit data between different application independent of platform.

A simple XML Document for Student List