Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Design > Adobe Creative Suite

From the book Working with DTDs

Working with DTDs

A Document Type Definition (DTD) is a text file that contains the “rules” for an XML file. There’s nothing magical about these rules—they’re just a formal version of the things you think about as you design and lay out a document. Heading levels, for example, follow a particular order; a numbered list must have at least two list items; last name data fields in directory data do not include middle names, and so on. Laying out documents is all about applying a structure to the data in the document (in addition to making it pretty to look at).

If, as we said earlier, an XML file can contain any data, in any order, how the heck can you work with other people? Most of us have, at one point or another, had some success training the writers and editors we work with to provide text files that are reasonably close to what we want. We’ve done this by giving them a detailed set of instructions on the way that they should prepare the text. And, at least for some of us, we’ve come up with a system that produces files that we can work with.

A DTD is something like a set of instructions for preparing a text file for page layout. But it’s much more than that, and somewhat more restrictive. At their best, DTDs provide an agreed-upon set of tags and XML data structures that work seamlessly with your publication processes.

DTD Basics

Given that there are entire books larger than this one on the topic of writing DTDs, you’ll have to forgive us for not going into great detail on the care and feeding of these files. (Besides, we’re still learning how to write them ourselves.)

The following are a few ground rules, however.

  • A DTD can exist as a separate file, or it can be inside an XML file. It’s most likely you’ll want to keep your DTDs as separate files, as it makes sense to work with a small set of DTDs (one or two) and apply them to a much larger number of XML files.
  • DTDs have four basic parts (called declarations): document type, comments, elements, and attributes.
  • If a DTD is included in a file containing XML data, the DTD is enclosed within the DOCTYPE declaration. This specifies the name of the top level (or “root”) element in the XML file. If the DTD is a separate file, it does not use the DOCTYPE declaration
  • Element declarations specify the name of each element—and therefore each tag—in an XML document.
  • Attribute declarations usually contain information about the information in an element (“metadata”), but they sometimes contain other data.

A (Very Brief) DTD Primer

As we mentioned above, DTDs have four basic parts: the DOCTYPE declaration, elements, attributes, and comments. The following sections provide a a bit more detail on each part.

Document type.

If the DTD appears in a file containing XML data, the DOCTYPE declaration appears at the beginning of the file, immediately following the XML declaration. The skeleton of this type of file looks something like this (in the following, the XML element “author” is the root element):

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE author [
<!-- DTD for author -->
]>
<author>
<!-- XML data-->
</author>

If the DTD is not included in an XML file, then you can omit the DOCTYPE declaration. We’re not exactly sure why you would include the DTD with the XML file, but you have the option to do so, should you so desire.

Comments.

Once you venture beyond simple DTDs (such as the examples in this book), you’ll find that it gets difficult to keep track of all of the elements and attributes in a DTD file. When this happens, you’ll want to add a note to yourself—or to anyone else who might happen to be reading the DTD—explaining what, exactly, you’re trying to do with a specific line or section of the file. Comments are preceded by “<!--”, end with “-->”, and can be span multiple lines. Here’s an example comment:

<!-- No more than one social security number per author -->

Elements.

Elements are the heart of the DVD. They specify the structure of the data used by the DTD, and they correspond to the XML tags in InDesign. Each element declaration contains the name of the element and the data that the element contains. A simple element declaration looks like this:

<!ELEMENT first (#PCDATA)>

This declares that the element is named “first,” and that the element contains text (that’s what “PCDATA” means).

A slightly more complex element is shown below.

<!ELEMENT name (first middle? last)>

This element is named name, and is made up of three elements, “first,” “middle,” and “last.” The question mark after the element “middle” means that this element is optional. Other marks specify other things about the content of the element—see Table 14-2.

Table 14-2: Element Codes

Symbol

What it Means

+

Required, and may repeat (one or more of these elements may appear in the parent element).

?

Optional, but may not repeat (only one of these elements can appear in the parent element).

*

Optional, and may repeat.

no mark

Required, and cannot repeat.

,

elements in an element. If an element name is followed by a comma, elements following the comma must appear after the element.

|

names, it means that either or both of the elements can appear; if one of the element names is required, then one or both elements must appear

Attributes.

An attribute contains additional information about an element. Attibutes are generally used for storing metadata (again, that’s data about the data in the element, not necessarily data you want to print out—the date the element was created or updated would be examples of element attributes).

An example attribute looks like this:

<!ATTLIST address updated CDATA #IMPLIED>

Attribute declarations are lists with four parts: the element name, the attribute name, the attribute type, and whether or not it’s required. In the above example, the attribute is associated with the “address” element, the attribute is named “updated,” the attribute contains the data type CDATA (text), and it’s optional.

The attribute options for the last parameter (“required”) are:

  • #REQUIRED means the attribute is required.
  • #IMPLIED means the attribute is optional.
  • #FIXED is always followed by a value; if the attribute is missing, then it’s assumed to be this value.
  • Some default value. This is really the same as #FIXED, above, in that the value provides the default value.

An Example DTD

Given our very simple XML database example, we can construct a DTD to use for validating new versions of the database. It would look something like the following.

<!-- DTD for author -->
<!ELEMENT author (name, address, city, state, zip)>
<!ELEMENT name (first, middle, last)>
<!ELEMENT first (#PCDATA)>
<!ELEMENT middle (#PCDATA)>
<!ELEMENT last (#PCDATA)>
<!ELEMENT address (#PCDATA)>
<!ELEMENT city (#PCDATA)>
<!ELEMENT state (#PCDATA)>
<!ELEMENT zip (#PCDATA)>

Importing DTDs

To import a DTD file into an InDesign document, follow these steps (see Figure 14-26).

Figure 14.26 Importing a DTD

  1. Display the Structure view, if it’s not already visible (choose Show Structure from the Structure submenu of the View menu, or click the Show Structure button at the lower-left corner of the InDesign window).
  2. Chose Load DTD from the Structure menu. InDesign displays the Load DTD dialog box.
  3. Locate and select the DTD you want to import, then click the Open button. InDesign imports the DTD.

When you import a DTD, InDesign adds the tags in the DTD file to the list of tags in the Tags panel. The tags defined in the DTD are locked—you can change the tag’s color, but not the tag’s name.

To view the DTD, choose View DTD from the Structure menu. InDesign opens the DTD in the View DTD dialog box—something like a very simple text editor (see Figure 14-27). You can scroll through the text, and you can select and copy text out of the DTD. We’re not exactly certain how useful this feature is, though we admit that it might come in handy during an “am I losing my mind or is that XML element really messed up” moment.

Figure 14.27 Viewing a DTD

“Off the Shelf” DTDs

Before you take on the task of creating a DTD from scratch, take a look at the DTD links http://www.xml.com/pub/rg/DTD_Repositories.html—you might find one there that will work for you, or at least find a good example. If you work in the newspaper industry, you might want to take a look at NewsML and SportsML, two DTDs developed by International Press Telecommunications Council (IPTC), at http://www.newsml.org.

Validating XML

Now we get to the fun part—checking an XML file to make certain it conforms to the DTD we’ve loaded. To validate XML elements, select the element and then click the Validate button at the top of the Structure view (see Figure 14-28). To validate a specific element, select the element and choose Validate From Selected Element from the Structure menu.

Figure 14.28 Validating XML

After InDesign has validated the XML, a new pane appears at the bottom of the Structure view. In this pane, InDesign displays the result of the validation. If there are errors in the XML (relative to the DTD’s specifications), then InDesign displays the offending element names in red, and lists the errors and possible solutions—the solutions are shown in blue, and are underlined.

To apply a solution, click it. This will not always solve the problems with the XML file, and it will sometimes introduce new problems. Luckily, this action can be undone—which means that you can experiment with different solutions to find which works for you.

Real World DTDs

By the time a file gets to you, it’s already too late. It needs to be laid out, proofed, and the final version printed by the deadline—and the editors, writers, and everyone else have already gone home for the night. If there’s an error in the copy you’ve been given, you don’t have time to go through proper channels—you just have to fix it. If the text files use the wrong styles, or if the graphics are in the wrong format, you can fix them and still have a chance of meeting your deadline.

If, on the other hand you, a file doesn’t conform to the DTD you’re required to use, you have a painful choice: you can start editing the XML file itself (painful and slow for all but the simplest XML files), you can turn off DTD validation and attempt to make sense of the XML structure, or you can stick to the “letter of the law” and reject the XML file because it didn’t conform to the DTD.

Publishing is about deadlines, more deadlines, and output. Keeping a press waiting is an expensive business, as the authors know to their bitter experience. We can add all of the formal handoffs, review processes, and conform to every standard that’s ever been formulated, but, in the end, we sometimes have to throw it all out the window in order to get the pages out the door.

We’re not saying that you shouldn’t use DTDs. But we did want to caution you—if you’re going to commit to a particular DTD, make certain that you build plenty of time into your process for validation and for fixing XML files that won’t validate.

Peachpit Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from Peachpit 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 Peachpit 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 ask@peachpit.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 Adobe Press. 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.peachpit.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