Magazine
 
XML : DTD
 

important to the software that wants to manipulate the element:

<file type=”gif”>roseindia.gif</file>

Use the quote styles: “red” or ‘red’

Attribute values must always be enclosed in quotes. Use either single or double quotes eg..

<color=”red”>

or like this:

<color=’red’>

Note: If the attribute value itself contains double quotes it is necessary to use single quotes, like in this example:

<name=’Rose “India” Net’>

Note: If the attribute value itself contains single quotes it is necessary to use double quotes, like in this example:

<name=”Rose ‘India’ Net”>

Use of Elements vs. Attributes

If you start using attributes as containers for XML data, you might end up with the documents that are both difficult to maintain and manipulate. So the user should use elements to describe the data. Use attributes
only to provide data that is not relevant to the reader. Only metadata (data about data) should be stored as attributes, and that data itself should be stored as elements.

This is not the way to use attributes eg..

<?xml version=”1.0" encoding=”ISO-8859-
1"?>
<E-mail To=”Rohan” From=”Amit”
Subject=”Surprise....”
<Body>Be ready for a cruise...i will catch u
tonight</Body>
</E-mail>

 

Try to avoid using attributes in few of the situations.

Lot of problems occur with using attributes values. They are not easily expandable and cannot contain multiple values. They are not easy to test against a Document Type Definition and are also unable to describe their structure. Becomes more irritating, because of its difficultly to get manipulated by program code.

Here is an example, demonstrating how elements can be used instead of attributes. The following three XML documents contain exactly the same information. A date attribute is used in the first, a date element is used in the second, and an expanded date element is used in the
third:

<?xml version=”1.0" encoding=”ISO-8859-
1"?>
<E-mail date=”15/05/07">
<To>Rohan</To>
<From>Amit</From>
<Subject>Surprise....</Subject>
<Body>Be ready for a cruise...i will catch u
tonight</Body>
</E-mail>

First xml document contains date as a attribute which can not be further extended. But date used a element in second document makes it more flexible.

<?xml version=”1.0" encoding=”ISO-8859-
1"?>
<E-mail >
<date=”15/05/07">
<To>Rohan</To>
<From>Amit</From>
<Subject>Surprise....</Subject>
<Body>Be ready for a cruise...i will catch u
tonight</Body>
</E-mail>

Second xml document can be further extended as.

Jan 2008 | Java Jazz Up |28
 
previous
index
next
 
View All Topics
All Pages of this Issue
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

58
, 59, 60, 61, 62, 63 , 64, 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 ,

83, 84 , 85 , 86, 87 , 88, 89 , 90 , 91 , 92 , 93 , 94 , 95 , 96 , 97 , 98 , 99 , 100 , 101 , 102 , 103, 104 , 105 ,

106, 107,

Download PDF