XML - Attribute

> Markup Language (ML) > Extensible Markup Language (XML)

1 - About

Attributes are used to associate name-value pairs with elements and are defined in a start tag of an empty tag.

The Name-Value pairs are referred to as the attribute specifications of the element.

In HTML, they are characteristics or descriptions for the content in the element.

Advertising

3 - Example

<termdef id="dt-dog" term="dog">

This Xml start tag defines:

  • for the attribute name “id” the attribute value “dt-dog”
  • for the attribute name “term” the attribute value “dog”

HTML Specification: The attribute value can remain unquoted if it doesn't contain space characters or any of “ ' ` = < or >. Otherwise, it has to be quoted using either single or double quotes. The value, along with the ”=“ character, can be omitted altogether if the value is the empty string.

<!-- empty attributes -->
<input name=address disabled>
<input name=address disabled="">
 
<!-- attributes with a value -->
<input name=address maxlength=200>
<input name=address maxlength='200'>
<input name=address maxlength="200">

4 - List

All the attributes of an element are called the attribute list.

5 - Declaration

Attribute-list declarations specify the name, data type, and default value (if any) of each attribute associated with a given element type.

Example:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE TABLE [
        <!ELEMENT TABLE (ROW)*>
        <!ATTLIST ROW COL1 CDATA #IMPLIED>
        <!ATTLIST ROW COL2 CDATA #IMPLIED>
        <!ELEMENT ROW (#PCDATA)>
        ]>
<TABLE>
    <ROW COL1="25874" COL2="000005" />
    <ROW COL1="26084" COL2="000006" />
</TABLE>	

6 - Documentation / Reference

Advertising
markup/xml/attribute.txt · Last modified: 2017/01/20 18:12 by gerardnico