Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

XML Documents : Page 7

XML documents are similar to HTML documents. They contain information and markup tags that define the information, and are saved as ASCII text.


advertisement

Attributes
Attributes provide additional information about elements.

You use elements and attributes all the time in HTML. For example, in HTML, a tag such as <H1 align="center"> includes an element: H1, and an attribute: align and an attribute value: center.

In HTML, attributes allow you to specify additional information about your elements. Often this information is formatting-related, such as align or size. In XML, attributes allow you to specify additional data about an element, but it is never formatting-related. It is, instead, additional data about that particular element.



Let's say, for example, you're creating documents about late 20th century popular music. In your DTD you've created an element called <SONG> which identifies each musical title. You have music that falls into different decade categories -- the 70's, the 80's and the 90's. You can give the song element an attribute called era. Now, you'll be able to know from what era each song dates.

By using an attribute, you can identify different versions of the same song -- "I've Got You Babe" from the 1960s and "I've Got You Babe" from the 1980s. Later on, you can use this data to display all 70s songs in green, or to sort the displayed titles by era.

You would use the attribute like this:

<SONG era="60s">I've Got You Babe</SONG>

<SONG era="70s">Billy Don't Be a Hero</SONG>

<SONG era="80s">I've Got You Babe</SONG>

"I've Got You Babe" is identified as a "song" element with an "era" attribute value of "60s". "Billy Don't Be A Hero" is identified as a "song" element with an "era" attribute value of "70s". "I've Got You Babe" is identified as a "song" element with an "era" attribute value of "80s".

Attributes and their allowable values are created in your DTD, when you specify elements. They are specified through an attribute list. Like element names, attribute names are case-sensitive, so be aware of your use of capitalization when you select and use attribute names.

One other important thing to remember about attributes in XML tags is that the attribute values must always be contained inside quotes. In HTML it's a mixed bag, but in XML the rule is easy to remember: quote all attribute values.





Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date