XML elements can have attributes. By the use of attributes we can add the information about the element.
XML attributes enhance the properties of the elements.
Let us take an example of a book publisher. Here, book is the element and publisher is the attribute.
<book publisher="Tata McGraw Hill"></book>
Or
<book publisher='Tata McGraw Hill'></book>
Metadata should be stored as attribute and data should be stored as element.
<book> <book category="computer"> <author> A & B </author> </book>
Data can be stored in attributes or in child elements. But there are some limitations in using attributes, over child elements.
In the context of documents, attributes are part of markup, while sub elements are part of the basic document contents.
In the context of data representation, the difference is unclear and may be confusing.
Same information can be represented in two ways:
1st way:
<book publisher="Tata McGraw Hill"> </book>
2nd way:
<book> <publisher> Tata McGraw Hill </publisher> </book>
In the first example publisher is used as an attribute and in the second example publisher is an element.
Both examples provide the same information but it is good practice to avoid attribute in XML and use elements instead of attributes.