Tuesday, July 17, 2007

Some Basic infos in XML

Components of an XML document :

1.Processing Information (PI )
2.Tags
3.Elements
4.Content
5.attributes
6.Entities
7.comments
1.Processing Instruction (PI) :

An XML document usuaally begins with the XML declaration statement called the Processing instruction .
The PI statement provides information on how the XML file should be processed.
The PI statement can be written as :



the PI statement must be written in lower case letters.

UTF-8 specifies the encoding scheme used to create the XML file.

2.Tags :

tags are used to specify a name for a given piece of information. A tag consists of opening and closing angular brackets.
start Tag <>
End Tag

example :

Sundar



3.Elements
Elements are basic units used to identify and describe the data in XML.

Elements are represented in Tag.

Example :

williams - author is an element.

XML document must always have a root element.A root element contains all other elements in the document.



charles dickens
Hitchkock


authors element contains all other elements in an XML and it is the root element.
XML document can contain only one root element.

4.Content

content refers to the information represented by the elements of an XML document.

Example :
Harry Potter

Harry Potter is the content .

XML enables us to declare and use elements that can contain different types of information.An element can contain :

1.character or data content
2.Element content
3.combination or mixed content


Example for character or data content (textual information )
--------------------------------------------------------
Harry Potter

Example for Element content (contains other elements)
--------------------------------------------

Elements can contain other elements. this other elements are called child elements.


charles
Dickens


author element contains FirstName and LastName elements.

Example for Combination or mixed content : (textual as well as other elements)
-------------------------------------------------------------------


The product is available in two colors
Red
Green


Attributes :
------------------------
Attributes provide additional information about the elements in which they are declared.
An attribute consists of name-value pair.

Example :
Barbie Doll

ProdId ="P001" is an attribute.

Elements can have one or more attributes.

Element is used to represent definable unit.
An attribute is used to represent data that further qualifies the element.

Example: font element can have an attribute color to specify the font color. In this case color attribute further qualifies the font element.


Entities :

An Entity is a name that is associated with a block of data, such as chunk of text or a reference to an external file that contains
textual orm binary information.

certain characters, such as <>) symbol
& used to display the ampersand (&) symbol
" used to display the double quote( " ) symbol



Example :

the price of the toy is < 200

entity (< ) replaced with the < symbol in the above statement. Comments : Comments are statements to explain the XML code. They used to provide documentation information about the XML file. The parser ignores comment entries during code execution. Comments are created using an opening angular bracket followed by an exclamation mark and two hyphens. This is followed by the text that comprises the comment. Comments are closed using two hyphens followed by a closing angular bracket. Example :



Rules for creating well formed XML documents :

The rules that govern the well formed XML document are

1.Every start tag must have an end tag.

2.Empty tags must be closed using a forward slash. Example :

3.All attribute values must be given in double quotation marks. Example :

4.Tags must have proper nesting . Opening tags must be closed in reverse order in which they appear.

incorrect format :
John grisham The client

Correct format :
John grisham The client

5.XML tags are case-sensitive.

0 comments: