If the element in question could be considered a property (CUSTOMER_NAME) of another entity (let's say CUSTOMER), the element can have zero or more attributes (properties) of its own (CUSTOMER_NAME is of TYPE = "KINDOFTEXT").
C++ C++ has support for both attributes and annotations.
C++11 added attributes, which are indicators to the compiler of some information. However, they are either standard-defined or implementation-defined, and custom attributes cannot be created. class Integer { private:
no_unique_address int x; public:
nodiscard bool isPositive() const noexcept { if (x > 0)
likely { return true; } return false; } };
C++26 added annotations which can be created, and can be accessed using
reflection, allowing arbitrary metadata to be attached. import std; using std::string; // some annotations defined in namespace wikipedia::examples using wikipedia::examples::Debug; using wikipedia::examples::EnumFlag; using wikipedia::examples::Rename; enum class
=EnumFlag Toggle: uint8_t { Off, On }; struct
=Debug Person {
=Rename("full name") string fullName; int age; };
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. In contrast, properties, in C# terminology, are members of a class which syntactically are used like instance (or class) variables, but are implemented as a pair of getter/setter functions. (In the absence of a setter, properties are read-only.) 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 that [Obsolete("Use class NewClass instead", IsError = true)] public class ObsoleteClass { // ... } public class NewClass { // ... } // class name ends with "Attribute" // but can be used as "Obsolete" public class ObsoleteAttribute : Attribute { public string Message { get; } public bool IsError { get; set; } public ObsoleteAttribute() {...} public ObsoleteAttribute(string msg) {...} public ObsoleteAttribute(string msg, bool error) {...} } [Obsolete] [Obsolete("This is obsolete")] [Obsolete("This is obsolete", false)] [Obsolete("This is obsolete", IsError = false)] 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. Check me document.getElementById('check1').addEventListener('change', function(e) { var input = this; var p = document.querySelector('p'); p.innerHTML = "input.checked: " + (input.checked ? 'true' : 'false') + "" });
Java The
Java language uses annotations to carry metadata on symbols or perform code generation, and can be accessed using reflection. abstract class Animal { public abstract void speak(); public String getType() { return "Generic animal"; } } class Cat extends Animal { @Override public void speak() { System.out.println("Meow!"); } @Override public String getType() { return "Cat"; } }
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 (elements). Note that the element's value is found before the (separate) end tag, not in the element itself. The element itself may have a number of attributes set (NAME = "IAMAPROPERTY"). If the element in question could be considered a property (CUSTOMER_NAME) of another entity (let's say CUSTOMER), the element can have zero or more attributes (properties) of its own (CUSTOMER_NAME is of TYPE = "KINDOFTEXT"). ==See also==