![]() |
|
| • All Online Courses • New Courses • QuickTips • Word Definitions • Submit a Tutorial • Links • |
|
Learn XML programming in this free XML training course What are attributes?When creating DTD’s, you sometimes find yourself using attributes instead of elements to create usage rules for your XML documents. Attributes are a lot like elements, and are defined in an attribute list (as mentioned previously.) A lot of questions exist as to when attributes should be used and when elements should be used instead… as a basic rule, though, you should keep your definite content (text, and other types of data) in elements, and use attributes to handle metadata, or the information about the text or real data that’s contained within the elements. Let’s look at our sample attribute list from before: <!attlist cat_characteristics hair_length #implied hair_color #required name #required > As you can see, this list defines various attributes of the element, cat_characteristics. The attributes given are hair_length, hair_color, and name. Two of these are required, and one is implied… what all of this means is that when your document starts to be accessed, the program accessing it is going to find an element named cat_characteristics. To use this element, it’s going to have three pieces of information to find… those are your attributes. Looking at the attribute list, though, it will determine that one of the pieces might not be available… so it will search for the three pieces, and as long as it finds the two required attributes then it will be able to go on to the next bit of code with no problem. If it can’t find the required attributes, then it knows that it doesn’t have enough information to use the element, and is therefore unable to continue and displays an error message. Of course, if you wish you could do things a bit differently… there’s technically nothing wrong with storing your data in attributes, and using elements to create the rules by which the attributes are used. Unfortunately, this can be a bit confusing in the long run. Much like elements, there is a specific set of jargon associated with attributes… in addition to #required and #implied, you can also use #fixed (which means that there’s a definite value for the attribute, and it can’t be changed) or enter a value, as well as a variety of different keywords to create your data attributes. The list of attribute modifiers is:
An example of the format for using these keywords is as follows: <!attlist cat_characteristics hair_length CDATA #implied hair_color CDATA #required name IDREF #required > As you can see, both hair_length and hair_color are to be defined as character data, whereas name is a reference to the value of another element.
by John Casteele Find more free Internet tutorials from Learnthat.com. More Information:
Help us by rating this tutorial: [---] [--] [+] [++] [+++] [---] lowest; [+++] highest
|
|
||||||||||||||||||||||||||||
![]() |
Learn: Free
Tutorials - Links
to Free Tutorials
Understand: Free Technical Definitions
- ExplainThat Whitepapers
Use: Certification Section -
Discussion Forum
Visit Our Network Sites:
About Us : Contact Us : Advertise : Privacy Information