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
We should not give like this
These two are In valid naming .
Elements are used to represent the hierarchical structure look at the following example
<Title> MY FAMILY </Title>
<Children> Child_Name </Children>
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 name ="John">;
<ESal> 15000 </ESal>
<EDesignation> Software engineer </EDesignation>
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