Attributes
Every element can have an unlimited number of attributes. Attributes are a special form of content. They are meant to represent unique properties that are bound very tightly to an individual element. Unlike the element's text content or subelement structure, the attributes tend to be very constrained.
An element can only have a single value for any attribute. A tag that contains two attributes with the same name produces a fatal error.
The XML document definition mechanisms allow us to define attributes unambiguously. We state which attributes each element may or must have. We establish the type of each attribute and we can limit its valid values. Default values can be specified by the data designer.
Validating XML parsers will insure that a document's attributes fit the constraints we've established. No other content can be validated this rigorously, so attributes have an important role in an XML document in transmitting critical data.
Flash Context
Attributes are organized in ActionScript as an associative array, which is a member of the element node object. The name of the attribute becomes the index into the array and the value becomes the string content of the associated array element. Parsing the value into numeric form (for example) is the responsibility of the programmer, although in practice it is often performed automatically by ActionScript's implicit casting operations.
Syntax
Attributes are presented as names and values joined with an equal sign (=).
XML
attrib = "value"
Attribute names must comply with the name constraints we studied earlier. Spaces are permitted but not required. Most important, the value must always be a quoted string.
Rules
Each attribute must have
the name
an equals sign
an open quote
a value
a close quote
It may include:
space.
Attribute values must not make references outside the document they appear in. (We will see later how these references are made in other parts of the XML document.)
Attribute values cannot contain a < character, except as <.
Examples of Attribute
name= "Anna" |
Simple value |
name= "Anna Leah" |
Value can contain whitespace. |
name= "&daughter;" |
Value can be an internal reference. |
url= "http://bigfun.net/index.xlm" |
Value can be a complex string. |
Speed= "4.5" |
Numeric values represented as strings |
Bad Examples
url= http://bigfun.net/index.xlm |
Forgot the quotes |
tag = "<IMG>" |
Forbidden character |
name = "&//bigfun.net:daughter;" |
Illegal external reference |
Speed = 4.5 |
Forgot the quotes again |