writing

Semantics of XML attributes

In this article we are going to look at the semantics of XML attributes.

They can be conveyed as 3 Us: Unique, Unordered, Unstructured.

Let’s look at each semantic in detail.

Unique

There can be only one attribute with a given name in an XML element.

For example this is correct:

<a href="#1">link</a>

while this is not:

<a href="#1" href="#2">link</a>

Unordered

The order in which attributes appear in an element does not matter.

For example these elements are equivalent:

<a href="#" id="link1">link</a>
<a id="link1" href="#">link</a>

Unstructured

The value of an attribute can only be text. It cannot contain nested XML elements or attributes.

For example even though the value of the id attribute in the following element contains XML syntax, it will not be parsed as such:

<a href="#" id="<source>1</source><value>link1</value>">link</a>

similarly there is no notion of nested attributes in XML:

<a href="#" id="source='1' value='link1'">link</a>

© 2022 Darius J Chuck