Lesson 2 | Declaring attributes in a DTD |
Objective | Determine the best way to use attributes in a DTD. |
Declaring Attributes in DTD
In HTML, you are familiar with using attribute values to provide information about tags.
For example, the INPUT
element provides a great deal of variety, depending on the value of the TYPE
attribute. A tag such as this:
<INPUT TYPE="text">
indicates a text box element. If the type is set to "radio"
, the INPUT
element becomes a radio button.
If the type is set to "checkbox"
, the INPUT
element becomes a check box, and so forth.
Attributes in XML
In XML, you can also use attributes either as attribute values within tags or as character data between tags.
However, SGML purists tend to look down on the practice of embedding useful information within tags, preferring to place useful information between tags. To determine how to use attributes in a DTD, think of what you want to show the user.
The following Slide Show shows various ways of using attributes:
Using DTD Attributes
Storage Unit
The storage unit that contains the XML declaration, the document type declaration, and the root element is called the document entity. Thus, every XML document has
at least one entity. However, the root element and its descendents may also contain entity references pointing to additional data that should be inserted into the document.
A validating XML processor combines all the referenced entities into a single logical document before it passes the document on to the end application or displays
the file.
Note: Nonvalidating processors may, but do not have to, insert entities defined in the external DTD subset. They must insert entities defined in the internal DTD subset.
The next lesson shows you how to declare lists of attributes.
log and the document type declaration are part of the root entity of the document. An XSL style sheet qualifies as an entity, but only because it itself is a well-formed
XML document. The entity that makes up the style sheet is not one of the entities that compose the XML document to which the style sheet applies. A CSS style sheet is not an entity at all.
Most entities have names by which you can refer to them. The only exception is the document entity, the main file containing the XML document (although thereâs no
requirement that this has to be a file as opposed to a database record, the output of a CGI program, or something else).
Entities can be either internal or external. Internal entities are defined completely within the DTD. External entities, by contrast, draw their content from another source located via a URL.
The main document only includes a reference to the URL where the actual content resides. Entities fall into two categories: parsed and unparsed. Parsed entities contain wellformed
XML text. Unparsed entities contain either binary data or non-XML text (such as an e-mail message). Currently, unparsed entities arenât well supported (if at all) by most browsers, editors, and other tools.