Tutorials » Xml tutorials »

XML Elements ans Attributes.


This article explains about elements and attributes


What is Element?


In XML element is a single thing, which matches values. Simply we can call that all our tags are elements. Since they used to represent our attributes. An element can be called as XML node.
Elements can have single value, multiple values or null values

Rules for 'element naming'


1. Names can be alphanumeric values can be mixed with some special characters
2. Names should not start with numbers ,special symbols
3. Names should not start with XML or xml

Example


<Emp1>
<Emp_name>


We should not give like this


<$Emp>
<123Emp>


These two are In valid naming .

Elements are used to represent the hierarchical structure look at the following example



<Family>

<Title> MY FAMILY </Title>

<Parents> Parent_Name

<Children> Child_Name </Children>

</Parents>

</Family>



Here Family is a Root element and Parents is Child element and inthat
Children is Child element of parent like wise elements are used to represent the hierarchical structure In the above example title is sibling

What is Attribute?


Attribute is a thing or real world entity. Simply here in XML we can say that the things which are written in side our tags ie inside the element are attributes .It's a property of an element.



<Emp>

<Emp name ="John">;

<ESal> 15000 </ESal>

<EDesignation> Software engineer </EDesignation>

</Emp name>

</Emp>



Here Emp name = "John" is an attribute. We shoul represent attribute with in quotes (single or double quotes)

Emp name can be represented with in attributes or child nodes

NOTE There are no restrictions like when to use attributes and when to use child nodes we can use any one but in XML many prefer to use child nodes





Previous Chapter: Our first XML file
More Chapters: Xml Tutorials
More Tutorials: Tutorial Index



Top Contributors
TodayLast 7 Daysmore...

Awards & Gifts
 
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India