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 series of images shows various ways of using attributes:
Document Type Declaration
DTDs are introduced into XML documents using the document type declaration (i.e., DOCTYPE). A document type declaration is placed in the XML document's prolog and begins with <!DOCTYPE and ends with >.The document type declaration can point to declarations that are outside the XML document (called the external subset) or can contain the declaration inside the document (called internal subset). For example, an internal subset might look like
The first myMessage is the name of the document type declaration. Anything inside the square brackets ([]) constitutes the internal subset. As we will see momentarily, ELEMENTand #PCDATA are used in element declarations. External subsets physically exist in a different file that typically ends with the.dtd extension,
although this file extension is not required. External subsets are specified using either keyword SYSTEM or PUBLIC.
For example, the DOCTYPE external subset might look like
<!DOCTYPE myMessage SYSTEM "myDTD.dtd">
which points to the myDTD.dtd document. Using the PUBLIC keyword indicates that the DTD is widely used (i.e., the DTD for HTML documents). The DTD may be made available in well-known locations for more efficient downloading.
The DOCTYPE
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
uses the PUBLIC keyword to reference the well-known DTD for HTML version 4.01.
XML parsers that do not have a local copy of the DTD may use the URL provided to download the DTD to perform validation.
Both the internal and external subset may be specified at the same time. For example,
the DOCTYPE
contains declarations from the myDTD.dtd document as well as an internal declaration.
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 are not well supported (if at all) by most browsers, editors, and other tools.