Home > Articles > Web Services > XML

Creating ATTLIST Declarations

ATTLIST is a container for the attributes associated with an ELEMENT. It has a straightforward syntax but complex alternatives that make it challenging to know every one:

<!ATTLIST element-name attribute-name-1 datatype default-data
            attribute-name-2 datatype default-data
            ... >

The following subsections define which datatypes can be used in an attribute list. For non-validating parsers, these datatypes are somewhat beside the point because the parser won't know anything about them. If your interest lies in downstream processing of XML documents using non-validating parsers, you can skip this whole section without much loss.

XML Datatypes

There are many more datatypes allowed in attributes than there are in content models. Where a content model allows only for PCDATA, attributes can take fairly specific datatypes. The XML attribute datatype defines in general terms what sort of information an entity can contain and how it will be structured. The attribute datatype is taken from the following list:

  • CDATA—Character Data is a string.

  • ID—A tokenized unique ID within a document. Although you're permitted to declare a default value, there's really no point in doing so. Also, because you need access to the DTD to determine whether there is an ID contained in the element, it's worthless to non-validating processors. Most tools that depend on IDs posit a theoretical ID with the name "id" that exists within every element and uses it whether it's been declared or not.

  • IDREF—A tokenized reference to a unique ID. See ID.

  • IDREFS—A tokenized list of references to unique IDs within a document. See ID.

  • ENTITY—A tokenized reference to an entity which refers to a notation. This is another way of referring to unparsed data.

  • ENTITIES—A tokenized list of references to entities which refer to notations. This is another way of referring to unparsed data.

  • NMTOKEN—A tokenized reference to a NAME token.

  • NMTOKENS—A tokenized reference to a list of NAME tokens.

  • NOTATION—An enumerated reference to a list of notation datatypes. This is an exception to the rule that all unparsed entities must be external. If you define an attribute of type NOTATION for an element, you can actually put your notation data inline within your document. Assuming that you would defined the attribute type as a NOTATION in the following XML example, you would be able to include JavaScript without an external reference, if and only if you're using a validating parser.

             <Script type="JavaScript"> ... JavaScript Code ... </Script>

    To say that you would have to be careful when you do this is an understatement. Note that it's not an error for an external user agent to fail to understand a notation, so the JavaScript may be rendered as simple text or ignored completely depending on the combination of parser and user agent.

  • ( attr1 | attr2 | ... )—An enumerated list of possible attribute values. Many XML authoring environments display these as a drop-down or pop-up selection list for ease of use.

Because multiple attributes can exist in a single element, an ATTLIST can get complex. They all obey the same set of rules, however, so careful study should set you right after any initial confusion.

The following subsections go into greater detail about the contents of attributes, starting with the default value syntax.

Specifying Default Data in an Attribute

The default-data placeholder in the attribute list template earlier in this section can be either #REQUIRED, #IMPLIED, or a default value; or #FIXED and a constant value.

These are working examples:

<!ATTLIST elementname attr1 #REQUIRED
           attr2 #IMPLIED
           attr3 "default-value"
           attr4 #FIXED "constant-value">

Both #REQUIRED and #IMPLIED don't take a default value because they would be meaningless in context. If the attribute is #REQUIRED, it has to be there whether there's a default value or not. If the attribute is #IMPLIED, the attribute is not necessary and need not be present.

NOTE

If ever there was a confusing term, #IMPLIED is it. It sounds almost like "default." You might naively think that the "implied" value was the default. But it isn't. Implied is there to tell the processor that it needn't bother looking for an attribute because it might not be there. The choice of words was an unfortunate lapse from clarity, nothing more.

IMPLIED is a holdover from the days of SGML, when straightforward description was sometimes sacrificed for a precise "logical" term whose origins lie hidden in the dusty mind of a programmer from the ancient days. In my opinion, the word is a simple malapropism because a somewhat related and often confused term, "inferred," describes precisely what the processor should do with an "implied" attribute, which is to infer the attribute's existence or non-existence based on the presentation of the element in the XML document itself.

Attributes of Type CDATA

This is really simple. It's a character string. The following example defines an attribute named string whose value is CDATA and a default value for that string:

<!ATTLIST name string CDATA "string stuff">

Note that, as always, non-validating parsers won't read the definition or default value of external DTDs.

Attributes of Type ID

These refer to unique IDs within your document and furnish an easy way to ensure that there is an available name to form the other end of a link. Although this is a clever thing to do, in practice most browsers are probably not going to validate and will never see the ID definition. Most current pointer tools impute the presence of an attribute of type ID named id or name whether it's in the DTD or not, thereby letting them generate links without tears.

The following code defines an ID attribute named node and then shows how the attribute might be used in an XML document.

DTD declaration: <!ATTLIST name node ID #REQUIRED>
XML document instance: <name node="A1234"

A safer course would be to define the ID attribute with the name id, so non-validating parsers can infer its intent just as HTML browsers do the name attribute. In the following section, you'll see two ways to do this.

Attributes of Type IDREF

This is a way to refer to the other end of an id/idref pair. The IDREF points to the id.

DTD declaration: <!ATTLIST anyname pointer IDREF #REQUIRED>
XML document instance: <anyname pointer="A1234"

In HTML terms, this is the rough equivalent of the href attribute that points to a named anchor.

NOTE

IDs are so handy it's a shame to have to plug them in everywhere, especially when you don't have write permissions on the source document. The next generation of linking mechanisms, XML XLinks and XPointers, will allow you to automatically use the document structure itself to obtain nearly the same result in the display document.

In an ideal world, IDs are the most likely artifacts to remain stationary, or relatively so, in a document. For this reason, they make good targets for pointers. The URL#namevalue fragment syntax used in HTML to point to locations within the document also works in XML, except that the target must be an ID.

The corollary to this is that both ID and name attributes should be declared for every possible target, because legacy user agents will find the element containing the indicated name attribute and XML-aware user agents will find the ID. You could, theoretically, collapse the two into one attribute by declaring a name attribute to be of type ID if you knew that the document would be viewed using validating XML parsers only. Unfortunately, the ID tag is also used in HTML, in a type of schizophrenia resulting from trying to keep the old syntax and create a new one that seemed more self-explanatory. So, it's best to declare two attributes with the same value. ID-type attributes must be unique within a document and name attributes should duplicate the ID-type attribute.

So ideally, one would define the following attributes in any element that might be used as the target of a hyperlink:

<!ATTLIST anylink id  ID   #IMPLIED
         name NMTOKEN #IMPLIED
         other-attributes... >

If you wanted to enforce the presence of the two link attributes on an element, you could define them as required like this:

<!ATTLIST anylink id  ID   #REQUIRED
         name NMTOKEN #REQUIRED
         other-attributes... >

Please note that the name attribute can't be of type ID, although it should duplicate the content of the id attribute, since the parser would enforce ID attribute uniqueness, preventing you from declaring a second instance of an attribute of type ID. In use, you could instantiate the target of a hyperlink like this:

<anylink id="A1234" name="A1234">anytargetcontent</anylink>

If the name of the anylink element were chosen to be a, both HTML-only browsers and XML-aware browsers would find the same location.

<a id="A1234" name="A1234">anytargetcontent</a>

This is the strategy used by XHTML, since it's designed in part to be accessible to as many legacy HTML browsers as possible as well as providing the benefits of extensibility for XML-aware browsers.

Attributes of Type ENTITY

This is how you would use an attribute of type ENTITY to refer to a notation:

<!NOTATION gif PUBLIC "...">
<!ENTITY gifpicture SYSTEM "mypicture.gif" NDATA gif>
<!ELEMENT picture EMPTY>
<!ATTLIST picture src ENTITY #REQUIRED>

In an XML document proper you would use the picture tag defined in the DTD like this:

<picture src='gifpicture'>

This is one more way that XML requires you to be a multimedia guru. Although I'm sure there's an important distinction between the many ways available to do this, the real question is whether it should be done at all. See my comments on notations in general earlier in this chapter.

TIP

I hate to harp on this and I promise not to do it after this chapter, but forcing the XML processor to know about all the possible multimedia types is not a robust way of doing things. In the first place, it means that you can't insert an image or multimedia file within a document unless you can guarantee that all your users will be using validating XML parsers. This seems excessively limiting. The W3C XML working group seems to have ignored the example of browser plug-ins and server-side redirection, which would have made it possible to negotiate with the user agent to ascertain its capabilities and supply an appropriate multimedia file if possible. If not, the user agent would know that it had to find an appropriate helper on its own, just as most now do with unrecognized MIME content types. A better mechanism should have been provided. Content negotiation between the browser and the server would have been the modern method of providing this flexibility, because different user environments might require entirely different file formats.

That said, the convention does work, even if it's awkward, and it may be replaced in the future with a simple mechanism that ignores the existing machinations in favor of some other method of identifying content type. The W3C standards for persistent URIs strongly discourage tying locations to data type and access methods, which the existing notation syntax violates.

Because the datatype might change in future, W3C currently recommends that content negotiation take place between the server and the user agent to determine what data types are supported and what types are available. In that case, you should refer to a notation as a bare name, like "myimage", and let the server figure out what kind of image is available for that particular agent and supply it, telling the agent what it supplied so there can be no mistake. It will all come out in the wash, as they say, so rest assured that this will undoubtedly change sometime in future.

Attributes of Type NMTOKEN

The contents of an attribute are constrained to look like a name token as defined in the XML Recommendation. In other words, it consists of one Unicode/ISO letter, ideograph, underscore, or colon followed by letters, ideographs, digits, periods, hyphens, underscores, or colons repeated as often as you like in any combination. This means simply that a name can't start with a digit, period, or hyphen, although it may contain any of these plus underscores or colons after the initial character but no other typographical symbols like asterisks, slashes, strokes, ampersands, or the like. The phrase "letters and ideographs" includes the characters one would ordinarily use to indicate words in a given language. For example, in Chinese these might be single characters indicating complete words; in Japanese, characters indicating complete syllables; and in many languages, individual letters indicating consonants and vowels which are combined to form words. The potential combinations of these extend the meaningfulness of names to include almost the entire population of the world literate in any human language.

CAUTION

As stated previously, using colons is strongly discouraged because they're easily mistaken for a namespace prefix. Also, the string "xml" in any case combination is reserved.

These are NMTOKENS:

name
new_name
_name.name-suffix
name.suffix
:name
luftballoons99
name1.suffix_part

and these are not:

name&more
99luftballoons
.name
$value
name(function)

Although few texts on XML, in English at least, demonstrate the use of ideographs and non-Roman scripts in an element name due to the difficulty of typesetting them, among other reasons, the capability exists and will be used extensively in those areas that need this capability. Figure 3.3 shows an example of a Japanese language XML document available on the Web from the FujiXerox site at http://www.fxis.co.jp/DMS/sgml/xml/charset/utf-8/weekly.xml.

Figure 3.3 An example of a Japanese language document marked up with meaningful Japanese XML tags.

The link to this example was kindly supplied by the Chinese XML Now! site of Academia Sinica at http://www.ascc.net/xml/. The site contains numerous links to information of interest to developers of Chinese XML documents, test suites to confirm the capability to handle Chinese input properly, and examples of Chinese language XML documents.

Attributes of Type NOTATION

These have to match the NMTOKEN definition and are given in a simple alternation list that defines the enumeration of possible types. One of these can be chosen but not more than one. A default value can be specified but need not be. They look like this in use:

<!ATTLIST name type (gif87a|gif89a) >

The same NOTATION enumeration would look like this when defined with a default value:

<!ATTLIST name type (gif87a|gif89a) "gif89a" >

All notations must be declared before they're used in an attribute list.

Enumerated Attributes

Enumerated attributes look just like the previous examples and are defined using an alternation list, but don't refer to notations. They're handy for creating lists of choices. Most XML editing environments give you a little drop-down list for choosing which value you want out of the list. The following code demonstrates a simple enumerated attribute as defined in a DTD:

<!ATTLIST name choice (yes|no) >

Like NOTATION attributes, enumerated attribute values can take a default value:

<!ATTLIST name choice (yes|no) "yes" >

The above DTD snippet defines an attribute, choice, that can take the values "yes" or "no" and whose default value is "yes".

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020