Breaking News

Attributes In XML

Unlike in HTML, XML requires that all XML attributes have a value. This means all attributes have to be equal to something! Below is the correct way to create an attribute in XML.
 
If elements are nouns defining what something is, attributes are adjectives modifying the nouns. In general, data itself should be stored in elements, while information about the elements (or data) should be included in the attributes, as in:
 
<associate type=”silver”>Dharmendra Das</associate>
 
Type would be the attribute, “silver” the value. In the attribute/value pair, the value should always be enclosed in quotation marks. The attribute provides additional information about the element–in this example, enabling you to distinguish between silver associate, gold associates and diamond associate.
 
Remember, all attribute values must be wrapped in quotation marks.
 
For instance, you should use:
 
<associate type=”silver”>
rather than
<associate type=silver>
 
The type of quotes that you use around your attribute values is entirely up to you. Both the single quote ‘ and the double quote ” are perfectly fine to use in your XML documents.
 
The only instance when you might want to use one quotation over the other is if your attribute value contains a quotation or apostrophe of its own. Below are a couple of real world examples.
 
<jre version=’jre1.5.”Update 11″’>
<vendor>SUN</vendor>
</jre>
 

Check Also

XML and Server

Generating XML with JSP   XML can be generated on a server without any installed …