Learnthat.com Free Certification and Computer Online Courses
ThatNetwork.com Internet Media Network Exampractice.com free certification practice exams, mcse, comptia Definethat.com - Free technical definitions, define Free Romance Tips, Romantic Tips, Date Ideas Free POD publisher comparison print on demand
Learnthat.com Free A+ Certification, Computer Classes, Certification Courses, Business, Lifestyle, ApplicationsFree business tutorials and definitionsFree certification tutorials and definitionsFree computer and technical tutorials and technical definitionsFree Finance Tutorials and DefinitionsFree House Repair TutorialsFree Lifestyle and Fun Tutorials
  All Online CoursesNew Courses QuickTipsWord DefinitionsSubmit a TutorialLinks
÷ Resources
Home
free tech tutorials
Free Tutorials
free tech tutorials
Certifications
free tech tutorials
Definitions
free tech tutorials
Resources/Links
free tech tutorials
Forums
free tech tutorials
Distance Education
free tech tutorials
Highest Rated Tutorials
÷ Popular Tutorials
÷ New Tutorials

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:

CDATA

The value is character data

(en1|en2|..)

The value must be one from an enumerated list

ID

The value is a unique id

IDREF

The value is the id of another element

IDREFS

The value is a list of other ids

NMTOKEN

The value is a valid XML name

NMTOKENS

The value is a list of valid XML names

ENTITY

The value is an entity

ENTITIES

The value is a list of entities

NOTATION

The value is a name of a notation

xml:

The value is a predefined xml value

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:

DefineThat.com Technical Defintions Romancetips.com
Free Gift Ideas - GiveThat Planthat.com Free Unique Business Ideas
PublishOnDemand.net - Learn about Print on Demand (POD) - Self Publishing Seekthat.com - Technical Search Engine
ThatNetwork.com  

About Us : Contact Us : Advertise : Privacy Information

© 1998-2004 Learnthat.com