6.2. AttributesAttributes are a name-value pair that is contained in an element's start tag. The name portion of an attribute is separated from the value by an equals sign, and the value is enclosed in either single or double quotes. Elements can have multiple attributes, separated from one another by whitespace, usually one or more spaces. It is not unusual for XML documents to use a combination of container elements and attributes. Listing 6-5 shows what the XML document in Listing 6-4 would look like using attributes. Listing 6-5. An XML Document with Attributes
Before proceeding any further, I want to cover the three rules for the naming of elements and attributes; these rules are only slightly more complex than the rules for the addressing of cats. The first rule is that only alphanumeric (az, 09) characters, the underscore (_), the hyphen/dash (-), and the colon (:) are permissible in names. The second rule is that names can begin only with an alpha, underscore, or hyphen character. The third and final rule is that names are case sensitive, so Mistoffelees is a different animal than MISTOFFELEES, and mistoffelees is yet another animal. Think of these rules as a practical guide, and you won't have any problems with names. |