Similar to HTML, XML elements can have attributes that are designed to contain data related to a specific element.
XML Attributes Must be Quoted:
Being always quoted, the attribute values can have either single or double-quotes.
or like this:
If the double quotes are already present in the attribute value itself then we can use single quotes.
or we can also use character entities to serve the same purpose:
XML Elements vs. Attributes:
male Tom Smith
In the above examples, gender is an attribute in the first example and is an element in the second example. However, both have the same information. We can use either of the attributes or elements in XML.
The below three XML documents have the same information:
2020-06-04 Sapna Tom
In the above example, we used a <date> element.
2020 06 04 Sapna Tom
In the above example, we used an expanded <date> element.
Things to consider while using XML attributes:
- XML attributes cannot contain multiple values, but XML elements can.
- XML attributes cannot contain tree structures, but XML elements can.
- XML attributes are not easily expandable.
XML Attributes for Metadata:
The ID references assigned to the elements are used to identify XML elements. It is similar to the id attribute in HTML. For identifying the different notes, we use the id attributes, but they are not a part of the note itself. The metadata i.e., the data about data is to be stored as attributes. However, the data itself should be stored as elements.
Sapna Tom MeetingMonday at 11 AM! Sapna Tom Re: MeetingThanks for the reminder!