Showing posts with label XML. Show all posts
Showing posts with label XML. Show all posts

Wednesday, July 18, 2007

XML Schema

Data types in XML schemas :
-------------------------------
1.primitive data types
2.derived data types
3.Atomic
4.List
5.union

Primitive datatype :
------------------------
primitive data types are fundamental datatypes of XSD.
These data types are the basis for defining other data types in XSD.
Primitive datatypes do not contain elements or attributes.
They contain only values.

Primitive Data type Description

string Represents a collection of characters.

decimal Represents decimal numbers.

float 32 bit floating point numbers

boolean

timeDuration Represents certain duration of time

recurringDuration represents a time duration that recurs after a specific interval.


Derived data types :

Derived data types are defined using other datatypes called basetypes.


Derived Data type Base Data type Description

integer Decimal

long Integer

nonNegativeInteger Integer

positiveInteger nonNegativeInteger

int Long

time recurringDuration

date timeDuration


Atomic data types :

Atomic data types can not be broken down into smaller units. These datatypes can be primitive or derived.
For Example, the string primitive data type cannot be further broken down into smaller units, such as characters.

List Datatypes :

Listdata types are derived data types that contain a set of values of atomic data types.For Example, we can derive a point list.


union datatypes :
Union data types are derived from the atomic and list data types .




The Purpose of XML schema : (XSD)

XML schema file is stored with .XSD extension.

XML schema file is used to validate the XML file. In other words, whether the XML file is formulated according to our user requirement can be tested with XML schemas .

XML file is nothing but an instance of a schema...

For Example :

we are defining structure as follows :



struct Allowance // This is what we call it as schema in XML, we call it as XML Schema available in .XSD file
{
float HRA;
float PF;
float ESI;
};



//XML instance this is similar to .XML file
Allowance s = new Allowance ();
s.HRA = 2000;
s.PF = 1000;
s.ESI = 200;



we can validate the .XML file based on the XML schema...

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.