How to declare attributes in DTD XML

Follow by Email

The attributes of an element are declared separately from the element declaration. The declaration of an attribute is as shown below:

<!ATTLIST  element_name  attribute_name  attribute_type  [default_value]> 

If more than one attribute is declared for a given element, such declarations can be combined as shown below:

There are ten different attribute types. Among them, most frequently used type if CDATA, which specifies character data (any string characters except < and &).

The default value of an attribute can be an actual value or a requirement for the value of the attribute in the XML document. The possible default values for an attribute are given below:

Declaring Entities

Entities can be defined so that they can be referenced anywhere in the content of an XML document, in which case they are called general entities. All predefined entities are general entities. Entities can also be defined so that they can be referenced only in DTDs. Such entities are called parameter entities.

An entity declaration is as shown below:

<!ENTITY  [%]  entity_name  “entity_value”> 

The optional percentage sign (%) when present in the entity declaration denotes a parameter entity rather than a general entity.

When a document includes a large number of references to the abbreviation HyperText Markup Language, it can be defined as an entity as shown below:

<!ENTITY  html  “HyperText Markup Language”> 

Any XML document that includes the DTD containing the above declaration can specify the complete name with just the reference &html;

When an entity is longer than a few words, its text is defined outside the DTD. In such cases, the entity is called an external text entity. The declaration of an external entity is shown below:

<!ENTITY  entity_name  SYSTEM  “file_location”> 

The keyword SYSTEM specifies that the definition of the entity is in a different file, which is specified as the string following SYSTEM.


Take your time to comment on this article.

Follow by Email

Add a Comment

Your email address will not be published. Required fields are marked *

Like the article? please consider sharing it. Thank you

Advertisment ad adsense adlogger