Sunteți pe pagina 1din 9

Getting Started XML

XML
eXtensible Markup Language is a text based structured language , used for presentation of the data. XML is an alternative for HTML , but HTML is more presentation centric and XML on other hand is more data centric. In other word HTML focused on how we present our data, but XML focused on the what data need to present.

HTML and XML


HTML
1. It is focused on how data need to present. i.e. formatting of data

XML
1. It is focused on which data need to present. i.e. data to present

2. It has its own predefine tag. e.g. <html>,<body><table> etc.

2. It is not having any predefine tags as HTML is having, here user can make its own tags as per his requirement.
3. We can link our database to XML directly, every reputed RDBMS has this feature.

3. We can't link our database to HTML format directly from database.

XML example
Pre-processor identifier <?xml version="1.0"?>

<rootElement> <childA attributeA=Value>


<childAChild/> </childA>

Root Element

Attribute

<childB>
<childBChild_1/> <childBChild_2/>

Child Element

</childB> </rootElement>

Xml Pre-processor
It is used for defining that our document is an XML document. It is an optional one, but it is recommended to have the pre-processor on every XML document .

Syntax :

<?xml version="1.0"?>

Xml Element
It is an building block for an XML Document , it having a collection of two tags, one is opening tag other is closing tag. Syntax :

<OpeningTag></ClosingTag> e.g. <Name>Hcl Infosystems</Name>

Types of Xml Element


Broadly we can divide the XML Element into two of following category 1. Normal Element : In this type of Element, an Element have the collection of opening and closing tags. e.g. <Candidate></Candidate> 2. Empty Element : In this type of Element, an Element have on one tag and that tag will closed with /. This type of Element can be used for specifing the attribute and its values. e.g. <Candidate Id=CDE002/>

XML Attribute
Xml Attribute is an additional information regarding respective element. It is used to provide additional information other than the value contain by element in its opening or closing tags.

Syntax:
<Element Attribute=value/> Or <Element Attribute=value>..</Element> e.g. <Candidate Id=CDE002/> Or <Candidate Id=CDE002></Candidate>

Rules of an XML Document


1. An Xml Document should contain one root element, which contain all other elements declaration. 2. Elements of XML Document are case sensitive , we must make sure that opening and closing tags should in proper manner. We cant write like <Name>...<name>. 3. All Attributes values should in double quotes, we need to write every attributes value in double quotes like <Name Id=DKI001> 4. Nesting of Elements should be proper following Last-in-first-out method. Like <A><B>...</B></A> 5. All empty Elements should closed with forward slash /.

S-ar putea să vă placă și