Attribute (computing)


In computing, an attribute is a specification that defines a property of an object, element, or file. It may also refer to or set the specific value for a given instance of such. For clarity, attributes should more correctly be considered metadata. An attribute is frequently and generally a property of a property. However, in actual usage, the term attribute can and is often treated as equivalent to a property depending on the technology being discussed. An attribute of an object usually consists of a name and a value; of an element, a type or class name; of a file, a name and extension.
For example, in computer graphics, line objects can have attributes such as thickness, color, dashing attributes, etc. A circle object can be defined in similar attributes plus an origin and radius.
In reference to computer systems, attributes are defined particularly for read or write attributes for specific read or write.

Attribute usage

If the element in question could be considered a property of another entity, the element can have zero or more attributes of its own.

C#

In the C# programming language, attributes are metadata attached to a field or a block of code like assemblies, members and types, and are equivalent to annotations in Java. Attributes are accessible to both the compiler and programmatically through reflection.
Users of the language see many examples where attributes are used to address cross-cutting concerns and other mechanistic or platform uses. This creates the false impression that this is their sole intended purpose.
Their specific use as metadata is left to the developer and can cover a wide range of types of information about any given application, classes and members that is not instance-specific. The decision to expose any given attribute as a property is also left to the developer as is the decision to use them as part of a larger application framework.
Attributes are implemented as classes that are derived from. They are often used by the CLR services, like COM interoperability, remoting, serialisation and can be queried at runtime.
The example shows how attributes are defined in C#:

// causes compiler message saying
public class C // that C is obsolete
public class ObsoleteAttribute: Attribute

Positional parameters like first parameter of type string above are parameters of the attribute's constructor. Name parameters like the Boolean parameter in the example are a property of the attribute and should be a constant value.
Attributes should be contrasted against XML documentation that also defines metadata, but is not included in the compiled assembly and therefore cannot be accessed programmatically.

HTML & JavaScript

Display the checked attribute and property of a checkbox as it changes.







attr demo










before click


.attr: checked
.prop: false
.is: false

after click


.attr: checked
.prop: true
.is: true

Multi-valued databases

On many post-relational or multi-valued databases systems, relative to SQL, tables are files, rows are items, and columns are attributes. Both in the database and code, attribute is synonymous with property and variable although attributes can be further defined to contain values and subvalues.
The first of these databases was the Pick operating system. Two current platforms include Rocket U2's Universe and InterSystems’ Caché.

XML

In XML, an attribute is a markup construct consisting of a name/value pair that exists within a start-tag or empty-element tag. Markup languages, such as HTML and XML, use attributes to describe data and the formatting of data.
A good example is the process of XML assigning values to properties. Note that the element's value is found before the end tag, not in the element itself. The element itself may have a number of attributes set.
If the element in question could be considered a property of another entity, the element can have zero or more attributes of its own.