26.01.2019 Views

XML Simplified

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Module 1<br />

Introduction to <strong>XML</strong><br />

1.4.9 Attributes<br />

Attributes are part of the elements. They provide information about the element and are embedded in<br />

the element start-tag. An attribute consists of an attribute name and an attribute value. The name always<br />

precedes its value, which are separated by an equal sign. The attribute value is enclosed in the quotes<br />

to delimit multiple attributes in the same element. An attribute can be of CDATA, ENTITY, ENUMERATION,<br />

ID, IDREF, NMTOKEN or NOTATION.<br />

Concepts<br />

An enumerated attribute value is used when the attribute values are to be one of a fixed set of legal<br />

values. The attribute of identifier type (ID) should be unique. It is used to search a particular instance<br />

of an element. Each element can only have one attribute of type ID. IDREF is also an identifier type<br />

and it should only point to one element. IDREF attributes can be used to refer to an element from<br />

other elements. An attribute of type NMTOKEN allows any combination of name token characters. The<br />

characters can be letters, numbers, periods, dashes, colons or underscores. An NMTOKENS type attribute<br />

allows multiple values but separated by white space. A NOTATION type attribute must refer to a notation<br />

declared elsewhere in the DTD. A declaration can also be an example for a list of notations.<br />

Syntax:<br />

<br />

The following code demonstrates an example of attributes.<br />

Code Snippet:<br />

<br />

<br />

Tom<br />

Federer<br />

<br />

Attributes have some limitations, which are as follows:<br />

‣ ¾ Unlike child elements, they do not contain multiple values and do not describe structures.<br />

‣ ¾ They are not expandable for future changes.<br />

‣ ¾ They are not easily manipulated by the code.<br />

‣ ¾ They are not easy to test against a DTD.<br />

<strong>XML</strong> <strong>Simplified</strong><br />

Version 1.0 © Aptech Limited

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!