XML elements can have attributes in the start tag, just like HTML. Attributes are used to provide additional information about elements. Attributes often provide information that is not a part of the data. In the example below, the file type is irrelevant to the data, but important to the software that wants to manipulate the element:
Use the quote styles: "red" or 'red'
Attribute values must always be enclosed in quotes. Use either single or double quotes eg..
or like this:
Note: If the attribute value itself contains double quotes it is necessary to use single quotes, like in this example:
Note: If the attribute value itself contains single quotes it is necessary to use double quotes, like in this example:
Use of Elements vs. Attributes
If you start using attributes as containers for XML data, you might end up with the documents that are both difficult to maintain and manipulate. So the user should use elements to describe the data. Use attributes only to provide data that is not relevant to the reader. Only metadata (data about data) should be stored as attributes, and that data itself should be stored as elements.
This is not the way to use attributes eg..
Try to avoid using attributes in few of the situations.
Lot of problems occur with using attributes values. They are not easily expandable and cannot contain multiple values .They are not easy to test against a Document Type Definition and are also unable to describe their structure. Becomes more irritating ,because of its difficultly to get manipulated by program code.
Here is an example, demonstrating how elements can be used instead of attributes. The following three XML documents contain exactly the same information. A date attribute is used in the first, a date element is used in the second, and an expanded date element is used in the third:
First xml document contains date as a attribute which can not be further extended. But date used a element in second document makes it more flexible.
Second xml document can be further extended as..