xml Building blocks Attributes


Attributes are name-value pairs associated with an element.

They are represented by values in single or double quotes inside the opening element tag, or the empty element tag if it is an empty element.

  <anElement foo="bar" abc='xyz'><!-- some content --></anElement>
  <anotherElement a="1"/>

Attributes are not ordered (unlike elements). The following two elements have the same sets of attributes:

<foo alpha="1" beta="2"/>

<foo beta="2" alpha="1"/>

Attributes cannot be repeated in the same element (unlike elements). The following document is not well-formed: <foo a="x" a="y"/> because the attribute a appears twice in the same element.

The following document is well-formed. Values can be identical, it is the attribute name that can't be repeated.

<foo a="x" b="x"/> 

Attributes cannot be nested (unlike elements).