• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Chapter 24. XML > To create a simple DTD:

To create a simple DTD:

Open a plain-text editor, such as SimpleText (Mac) or WordPad (Windows). Don't use Microsoft Word, as it won't save the file as plain text, and some characters may be changed upon saving.

Type a comment line stating what the root element will be. Comment lines are written as follows: <!- - comment text here - -> .


Declare (define) the root element as an element, and, in parentheses after the root element name, include the elements (your primary style sheet names) that are to become the next top level on the XML Tree on the XML Workspace palette. All elements are contained in the root element, and are expected to match content in the QuarkXPress file .


All elements must be enclosed, meaning that the line of code must start with “<!” and end with “>”.

Declare the elements that were listed in the parentheses in the previous step. End each non-container element line with “(#PCDATA)” (parsed character data) to tell the XML parser (the software that interprets XML data) that those elements can contain text and/or entity references or processing instructions. The elements can be declared in any order within the DTD .


For an instance like a story that contains different paragraph style sheets within it, declare a body element. Then, in parentheses, list all the child elements (the paragraph and character style sheet names from your story text) that you want to be contained within that element (body).

Figure 1. The body element is declared as a container element, and is the parent to the child elements that are listed within the parentheses. These child elements will match style sheets with the same name in the QuarkXPress story. On the XML Tree on the XML Workspace palette, the child elements will be nested under the parent body element.

DTD symbols

When placed at the end of an element name, the DTD symbols listed below indicate how many times that nested element will occur within the main element above it. These symbols provide greater flexibility for handling the order and frequency of content to be tagged into elements. They also display on the DTD Tree in the Edit Tagging Rules dialog box (see page 439).

No symbolonly one time
?zero (none) or one time
+one or more times
*zero (none), one, or more times

The vertical bar “|” represents an either/or option. Any one of these style choices can be present in the story. The exact order and presence of style sheets in the story isn't important, because the body element will use any one of those styles in its container of elements.

An asterisk “*” symbol after the closing parenthesis indicates that zero (none), one, or more than one occurrence of an element may occur in body text. (This code symbol helps prevent XML parsing errors.) By placing the symbol outside the parentheses, the body element can have none, one, or all the listed style sheet names present, in any order, and in any frequency, when the content of the QuarkXPress file is tagged. If an asterisk is inserted after an element, it will apply only to that element.

Declare the child elements, as listed in the previous step . In the Quark XPress file whose content you want to include, make sure all the paragraph and character style sheets are declared in one of these locations: the first ele-ment line, the body element line, or another container element line. The first element line must contain either all the elements or all the parent elements, with the parent elements themselves being declared in subsequent lines to show their child elements. You can only declare an element that has been referenced in the first element line or a parent container line.

Figure 2. Declare the child elements (listed in the body element) that will hold content from style sheets with the same name in the QuarkXPress story. In our example, the Body_bold element was created to handle words in the story text that have been styled with the Body bold character style sheet.

Include the <!ATTLIST ... > line (an attribute declaration). This code enables your browser to display the images that are referenced by the XML file. If you're not technically oriented, just copy the code in .


What is HTML:img?

Technically, the term HTML is being declared as a prefix—an abbreviation for the XML namespace. The full name of a namespace takes the form of a URL, thus ensuring that it's a unique term. The URL is not used to point to a specific Web page! The XML parser will now understand the term HTML (as used in the <!ATTLIST lines).

If you want to know the details, continue reading this step. Define the elementName (ebook), attributeName (xmlns:HTML signifies that the HTML term is using the XML namespace), attributeType (CDATA signifies character data; #FIXED signifies the content must be set to the value that immediately follows), and DefaultValue (the URL). This whole line of code tells a browser (e.g., Microsoft Internet Explorer) to interpret the element (HTML:img) that was declared in step 8 as an HTML <IMG> tag.

Declare the element HTML:img as EMPTY, since it will contain no text content. Next, declare another <!ATTLIST... > to define element HTML:img to have an attribute of src (the abbreviation for source) . The attribute is a reference to an unparsed, external entity. This allows Quark XPress picture items to be tagged to an element that contains an attribute, which holds the address and title of a picture file.


The container element “illustration” is declared to contain the HTML:img and Caption elements . We could have written <!ELEMENT illustration (HTML:img) > and included a caption child element, since they are in separate boxes. How these elements are declared in the DTD will determine how the item is dragged onto the XML Tree when content is tagged. (Tagging is discussed on page 442.)


Make sure your file matches the structure of our DTD example and uses your style sheet names. Then save the file as plain text with a .dtd extension.

Now you'll incorporate the DTD file into a new XML file.



Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint