Name


Name

A name describes an element. It is not unique: lots of elements can have the same name. Therefore, a name cannot be used to identify an individual element. Instead, it tells us the kind of element, similar to declaring the class of an object or the type of a variable. There are no predefined element types and (with a single exception explained later) there are no reserved element names . It is up to the user to create and maintain meaning.

Flash Context

Lexically, XML names are similar to ActionScript names. XML is slightly more permissive. There is a potential for trouble from two characters , the colon (:) and the period (.). These have special meaning in ActionScript but are permitted in XML names. Yet even in XML they imply a sense of namespace hierarchy. The colon is explicitly discouraged (though not forbidden) in the XML protocol. And use of the period seems only to invite disaster. We avoid the use of either one due to their use as namespace delimiters.

Of course there is no requirement that an application map XML names directly to ActionScript names. Most applications that tried to do so would come across an obstacle larger than a dot or two.

ActionScript names are unique within their scope (you cannot have two variables called "foo" on the same level). XML element names are very frequently identical to the names of their siblings. While ActionScript names serve to identify an individual datum, XML element names do not.

Syntax

The restrictions on names are simple. Names can use any letter in the alphabet. The alphabet does not have to be ASCII, Latin-1, or even 8 bit. XML supports Unicode and allows names in the current alphabet. Our examples, however, will all be within the Latin alphabet.

Case matters, but it is your choice. There is no standard practice for use of case in XML. Often element names are all lower case with dashes standing in for spaces:

 first-name 

Names can use any digits, but they may not start with a digit:

 first-name2 

XML defines no element names, but it does reserve all names beginning with the three letters "xml" (case insensitive), so xml-test is not a permitted name.

Rules

CHARACTER INITIAL INTERIOR SAMPLE
letters yes yes A B C a b c … §
digits   yes 0 1 2 3
underscore yes yes _
colon yes, but [1] yes, but [1] :
dot and dash   yes . ”
xml prefix   yes XML xml xML

[1] Colons should be avoided due to the namespace connotation.

Examples of Names
ADDRESS Street, city, etc.
player Contains personal data, such as an address
team Probably contains several player elements
_team Different kind of team element
team.mascot Just a simple name. The dot has no meaning.
team_mascot Alternative name
team-mascot Traditional XML name formation
Formula1 Digits can be included
test-xml Noninitial XML triplet is fine
Bad examples
xmlTEST Cannot begin with xml
9-iron Cannot begin with digit
team:player Legal, but very bad form unless team is a namespace


Flash and XML[c] A Developer[ap]s Guide
Flash and XML[c] A Developer[ap]s Guide
ISBN: 201729202
EAN: N/A
Year: 2005
Pages: 160

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net