XML Attributes
XML Attributes
- Attributes are the part of the Xml Elements. An Element contains multiple attributes. All are unique.
- By the use of attributes we can add the information about the element.
- XML attributes enhance the properties of the elements.

Learn XML - XML tutorial - Attributes - XML examples - XML programs
Syntax
<tag attibuteName=“attributeValue”>
Xml attribute Example
<author bookType="Classical">
//else
<author bookType=‘Classical’>
Attribute Vs Element
- Metadata should be stored as attribute and data should be stored as element.
<author bookType="Classical">
<name>Venkat</name>
<nationality>Indian</nationality>
</author>
Attribute vs Sub-element or Elements
- Attributes are part of markup, while sub elements are part of the basic document contents.
In the below code bookType is an attribute
<author bookType="Classical">
In the below code bookType is an element
<author>
<bootType>Classical</bookType>
</author>

Learn XML - XML tutorial - XML Attributes - XML examples - XML programs
Read Also
Accept Attribute in HTMLXML Attributes Rules
- An attribute name must be appear once in the same start-tag or empty-element tag.
- The value of the attributes within the quotation mark.
- They used either single or double quotes.

Learn XML - XML tutorial - Attributes With Quotes - XML examples - XML programs
- Attributes must contain a value. Some HTML coders does provide the attribute name without a value or it will equal true. This is not allowed in XML.
- The values must not contain direct or indirect entity references to external entities.
- Using an Attribute-List Declaration , an attribute must be declared in the Document Type Definition (DTD).

Learn XML - XML tutorial - Attributes Value - XML examples - XML programs
XML Tree Structure

Learn XML - XML tutorial - XML Tree Structure - XML examples - XML programs
XML Attributes Drawbacks:
- Attributes doesn’t have multiple values but child elements can have multiple values.
- Attributes cannot contain tree structure but child element can.
- Attributes are not easily expandable. If you want to change in attribute's vales in future, it may be complicated.
- Attributes cannot describe structure but child elements can.
- Attributes are more difficult to be manipulated by program code.
- Attributes values are not easy to test against a DTD, which is used to define the legal elements of an XML document.
How XML is Presented ?

Learn XML - XML tutorial - How XML is Presented - XML examples - XML programs