Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved

Chapter 2 XML Tools Palette : DTD

DTD
Resource
The DTD resource of the XML Tools palette enables the creation of a DTD (Document Type Definition), as defined by the W3C’s XML 1.0 Recommendation.
A DTD shares the same role as an XML Schema, describing the vocabulary and structures that may appear within an XML instance document. While DTDs are supported in XML 1.0-compliant parsers and applications, they offer very limited data typing and are considered the 'first generation' of XML schemas.
When a DTD resource is selected in your project, a set of new panels, menu options, and toolbar buttons are provided, helping you build and edit your DTD from a variety of different perspectives. Each panel provides access to a different set of tools. The multiple panels may show information simultaneously, but all of them combine to present a consistent view of your schema. This chapter describes each of the panels in detail.
Configuration Panel
When editing a DTD resource, the configuration panel provides two tabs for setting or viewing high-level properties.
Configuration
The Configuration tab has the following fields.
This is the name of the file when persisted. The *.dtd suffix will be automatically added.
Statistics
The Statistics tab is not editable. The tab displays the number of times a schema component type is used. The Statistics tab has the following fields.
 
Toolbar
For a description of the buttons that appear on the toolbar when editing DTD resources, see Toolbar Buttons.
Schema Menu
A Schema menu becomes available when editing a DTD resource. The Schema menu contains two submenus, View and Tools.
The View menu provides options to control the panels used for editing, organizing, and viewing your schemas. The Tools menu includes options for searching or editing your schema, checking your schema for errors, and defining reusable schema components.
The Schema menu options are described in Table 7.
Elements Panel
The elements panel enables you to view, create, and edit element and attribute declarations. The elements panel is typically the place you'll start defining your schemas.
The panel is divided into two parts: a graphical view of the content model (the content model diagram) and an editable list of element declarations and their content models (the element list).
The Element List
The element list, located at the bottom of the elements panel, is where much of the creation and editing of element declarations takes place. Each element is listed in a row of the table. Information that defines each item appears in columns across the table and includes the following (from left to right):
Table 25 Element List
Warning: Any changes made to unlocked declarations of an external parameter entity will be reflected in the external schema as well.
Note: Element names must begin with a letter and may contain other letters, numbers, underscores, dashes, and periods.
Type — Data types that constrain text -- like integer or date -- are not afforded by DTDs. Accordingly, selecting the Type option is equivalent to selecting the Text option.
Note: To create a reusable model group (internal parameter entity representing element content), choose Create Model Group... from the Insert drop-down menu. Alternatively, parameter entities can be defined and edited by way of the Schema>Tools menu.
Building Content Models: Occurrence and Sequence Indicators
For element content models, buttons are provided for applying sequence and occurrence indicators. Table 26 describes the Occurrence indicators. Table 27 describes the Sequence indicators.
 
Occurrence and Sequence indicators combine to make it possible to describe complex structures. For example, a memo might allow multiple entries in its To: and From: fields, multiple (or zero) entries in its Cc: field, a single entry for the subject, required content for the body, and an optional set of initials at the bottom for the typist. A MEMO element might therefore have the following content model:
 
(To+, From+, Cc*, Subject, Body, Typist?)
This declaration requires the MEMO element to contain, in sequence, one or more To elements, one or more From elements, zero or more Cc elements, a single Subject element, a single Body element, and zero or one Typist elements.
In other cases, a document needs to provide choices. A chapter might require an introduction, but then permit any combination of sections or sidebars. Sequence indicators, in combination with occurrence indicators, can make this possible. The content model for a chapter element might therefore look like this:
 
(Intro, (Section | Sidebar)*)
The Intro element could appear once (and only once) at the start of the chapter, and then Section or Sidebar elements could follow in any order. (This model is read as “an Intro element followed by zero or more Section or Sidebar elements”.)
Example: Building a Content Model
This section steps you through building a content model using the buttons provided in the Content Model column. Figure 49 shows a completed content model.
Figure 49 A Completed Content Model for a Book Element
You will build the content model for an element based on the structure of a book. The content model would likely include several elements, including a Title, an Author, multiple Chapters, maybe an Appendix (or several), perhaps a Glossary, and possibly an Index. Assuming these elements are already declared, the steps to build the content model for Book appear below:
1.
In the row for Book, click in the blank cell under the Content Model column. This is where the entry for the content model will be created. A series of buttons will appear. You should see the text cursor blinking inside the parentheses.
Figure 50 Content Model Column
2.
Figure 51 Element Declarations
3.
Select the first element to be part of the content model (in this case, we'll start with Title). Repeat this step, selecting each element that is part of the content model. It's best to select the sub-elements in sequence if possible, because as each sub-element is selected, a comma is inserted between items by default to indicate that they are in sequence. The sub-element will always be inserted where the cursor is placed in the content model.
Figure 52 Content Model
4.
Which items may be repeatable? Within a book, the chapters usually occur more than once, so this sub-element needs to be indicated as a repeatable item. Highlight Chapter in the Content Model, and click on the Repeatable button. This adds a '+' indicator after Chapter, to indicate it is repeatable. Likewise, there may be more than one appendix, so highlight Appendix and click Repeatable to add a '+' indicator after Appendix.
Figure 53 Repeatable Button
5.
Which items are optional? Within a book, a glossary or index may not always occur, so these sub-elements need to be made optional. Highlight Glossary, and click the Optional button. Likewise, highlight Index, and click the Optional button. This will place a '?' after each of these sub-elements, to indicate they are optional.
Figure 54 Optional Button
6.
Appendix is also an optional item (not all books have appendices). Highlight Appendix and click the Optional button. Because Appendix is now both optional and repeatable, it is indicated with an '*' after it. Press the <Enter> key or click anywhere else in the element list panel to complete the content model.
Figure 55 Adding Appendix
Building Content Models: Content Model Editor
If the space provided by the Content Model column is too small to see all of an element content model, select Expand from the Schema > View menu or press the Ctrl-E keys to bring up the Content Model Editor dialog box. The Content Model Editor provides more room for editing, making it easier to work with larger content models, and gives easy access to the elements and reusables (internal parameter entities). To add an element or reusable to a content model, click on its name. Occurrence and Sequence indicator buttons are also available in the editor. The Apply button adds the edited content model to the list, but leaves the editor open. The Cancel button closes the editor without making any changes to the content model in the list, while the Save button closes the editor and makes the changes. The Content Model Editor is shown in Figure 56.
Figure 56 Content Model Editor
Building Content Models with Reusables (Internal Parameter Entities)
While breaking schemas into modules is helpful in large-scale situations where entire sets of declarations are shared within schemas, there are many cases where smaller chunks of declarations can be usefully shared and centrally managed. The reusables (internal parameter entities) editors allow you to define pieces of declarations, which you can then reuse as appropriate. If you later need to make changes to that content, you just change the reusable, and all of the declarations using that reusable will be updated automatically.
When defining new reusables, four editors, described in the table below, are accessible by way of the Schema menu (Schema > Tools > Define Reusables). For each editor, you enter the name of the reusable in the text box at the top of the window, and its content in the large text area.
Table 28 Reusable Editor
Once your reusables are created, they become available as choices by way of the Insert button within the Content Model and Attributes column of the element list. Notice that parameter entities, when referenced, are prepended with a ’%’. Figure 57 illustrates the use of a reusable within a content model.
Figure 57 Referencing a Reusable Parameter Entity (Internal)
To edit or delete an existing group definition, select the Edit Reusables option of the Schema menu (Schema > Tools > Edit Reusable).
The Content Model Diagram
The content model diagram of the types panel graphically displays the content models in a DTD resource. It presents the relationships between elements (that is, parent elements, child elements, and so on) with diagrams and provides additional information about elements, such as their attributes and occurrence and sequence within a content model. You can use the content model diagram to read, explore, or edit your schemas.
See Content Model Diagram for more information about the content model diagram.
Attributes Panel
When selected from the Schema > View menu or upon clicking the Attributes button on the toolbar, the attributes panel becomes the primary panel for editing. The attributes panel is used to view, create, and edit attribute type declarations. While you can also create an element’s attribute in the element list, the attributes panel is required to specify an attribute’s data type, edit its constraints, indicate its use, and set a default value. The attributes panel is shown in Figure 58.
Figure 58 Attributes Panel
Each attribute is listed in a row of the panel. Information associated with each attribute appears in columns across the panel and includes the following (from left to right).
Note: Attribute names must begin with a letter and may contain other letters, numbers, underscores, dashes, and periods.
The Constraints column allows you to limit the choices available for attribute values. This column is only applicable if the enumerated type is selected in the Data Types column. In this case, the Edit Enums button loads the enumerations editor (the Enumerations tab of the properties panel), where you can specify a list of possible values (of the specified data type) for the attribute. For more information on constraining attribute values, see Properties Panel.
If the attribute’s usage is designated as default or fixed, enter the default or fixed value in the Value column. Choosing either optional or required and then entering a value in the Value column will produce an error message. Choosing either default or fixed and omitting a value in the Default column will also produce an error.
 
 
Example: Creating or Editing an Attribute
Attributes are created by declaring an attribute type in the attributes panel or by entering attribute names for an element in the element list of the elements panel.
Creation of an attribute type within the attributes panel consists of several steps. For example, assume you have an element Picture, with the attributes GraphicsType. GraphicsType is an attribute that tells us if a picture is a JPG, TIF, or GIF file.
Here are steps for declaring GraphicsType:
1.
Click on a blank line under the Attributes Name column. Enter the attribute name GraphicsType. Names must begin with a letter and may contain numbers, underscores, dashes, and full stops -- typically periods.
2.
Select the cell under the next column heading, Element, in the row for GraphicsType. Since we know this attribute will be used by the element Picture, type in Picture.
3.
An attribute type declaration, by default, sets the data type for an attribute to string. In this example, GraphicsType will be enumerated (that is, it will only ever have the value of JPG, TIF, or GIF).
4.
Click the Type button and select enumeration from the XML Types menu.
Since GraphicsType can be only be a JPG, TIF, or GIF, these values must be entered in the attribute type declaration.
5.
6.
7.
Figure 59 Enumeration Tab
As you enter values in the Enumeration tab, they are inserted in the Constraints column of the attributes panel. Notice that the JPG, TIF, and GIF entries are separated by the OR indicator ('|').
A default value can be entered for an attribute.
8.
To set the default value of GraphicsType to JPG, tab into the cell under the Use column for the row GraphicsType. Click the Select Use button to display a menu of choices. Choose 'default' from the drop-down menu.
9.
This completes the declaration for GraphicsType.
Overview Panel
When you choose Schema >View >Overview or click the Overview button on the toolbar, the overview panel loads to the left of the elements panel. The overview panel allows you to control the creation of schemas that use multiple modules, as well as explore the overall organization of your schema. The overview panel's tools let you build schemas from declarations in multiple files, create large composite schemas from sets of smaller ones, enhance reusability and simplify management. Figure 60 illustrates the overview panel with the right button menu activated.
Figure 60 Overview Panel
Overview Tree
The overview panel provides a tree-like overview of the schema structure. Each schema component type is represented by an icon, described in the table below.
A right-button menu is provided for each component in the overview tree. From the menu, you can cut, copy, paste or clear a declaration or module (removing it or changing its location in the schema). There is also an option to “Go to” or “Edit” the component, which will take you to an area to edit the selected item.
If the declaration is located in an external schema that has been added to the current schema, a menu option to unlock the module is provided. Before any edits can be made to included declarations (identified by a document icon with a red slash), the included schema must be unlocked. When a module is unlocked, the red line disappears from the document icon. When you are done editing the included declarations, you can right-click on the module and lock it again. .
Add Module...Button
The Add Module option of the overview panel allows you to include the declarations from another of your project’s schemas into the schema you are currently building (through an external parameter entity reference). To remove an included schema, right click on the included schema icon and select Clear from the pop-up menu that appears.
Example: Including declarations from another schema
When building a schema, it is often desirable to reuse components already declared in another schema.This example illustrates the steps required to include another schema’s declarations in your schema.
1.
2.
Figure 61 Overview Tree
3.
Properties Panel
When selected from the Schema > View menu or upon clicking the Properties button on the toolbar, the properties panel loads to the left of the elements panel. The properties panel includes three tabs -- Properties, Constraints, and Enumeration. When working with a DTD resource, only the Enumeration tab is applicable. When an attribute is of type enumeration, use the Enumeration tab to create a list of possible values.
Enumeration tab
The Enumeration tab allows you to enumerate allowable values for an attribute. Accordingly, the Enumeration tab becomes applicable when an attribute is declared to be of type enumeration. The Enumeration tab is shown in Figure 62.
Figure 62 Enumerations Tab of the Properties Panel
When an enumeration is applicable, the tab can be accessed by:
In the text box at the top of the Enumeration tab, enter a value and then click Add. Repeat this procedure for each of the possible values. The values will appear in the list box beneath the text box used for input. You can use the Up and Down buttons to reorder the values in the list. You can also select a value in the list and either Delete it or Replace it with a value entered in the text box at the top. As you edit the enumeration in the Enumeration tab, the current values are reflected in the Constraints column of the attributes panel.
Advanced Panel
When selected from the Schema > View menu, the advanced panel becomes the primary panel for editing. The advanced panel allows you to define or edit parts of a DTD that move beyond the description of document structures. The advanced panel consists of the Parameter Entities tab, the General Entities tab, the Notations tab, and the Processing Instructions tab.
Parameter Entities Tab
When working with a DTD resource, the Parameter Entities tab provides access to internal and external parameter entities definitions. Internal parameter entities are used to implement reusable declarations or text (Schema > Tools > Define Reusable), while external parameter entities are used to support the modular schema architectures provided by the overview panel’s Add Module feature. Users familiar with DTD syntax may prefer to add parameter entities directly through the Parameter Entities tab.
The parameter entities tab is divided into two panels. The top panel is used for internal parameter entities, whose values contain their replacement content directly, while the bottom panel is used for external parameter entities, which contain references to external files that contain content.
Internal parameter entities have only a name and a value. (Entity names must begin with a letter and may contain numbers, underscores, dashes, and full stops -- typically periods.) The value must contain either complete declarations (more common in external entities) or fragments of single declarations. Declarations may not cross entity boundaries, though they may contain multiple entities. Entities may also contain entities themselves.
For example, to create an entity named 'shortened' that has the value '(title, paragraph)' - an element content model - the entries shown in Figure 63 would be appropriate.
Figure 63 Creating an Internal Parameter Entity
Once you have created a parameter entity, you can reference it within other declarations. To use parameter entity content, simply reference the entity using the following syntax:
%entityName;
Figure 64 illustrates the use of a parameter entity within a content model.
Figure 64 Referencing a Parameter Entity within a Content Mode
l
External parameter entities have names and references to external resources. External parameter entities must have system identifiers (either a full or relative path name to another DTD in your project) and may optionally have public identifiers as well. An 'Include in DTD' check box is provided that makes it easy to include external modules in your DTDs. If the external DTD contains multiple declarations, you'll want to make sure it gets checked.
Modules that have been added through the overview panel will appear here, and modules added here will appear in the overview panel. When you add a module, its content is downloaded for use in the current schema. The parameter entity declarations for that module will also appear in the parameter entity window, preceded by an icon if the module hasn't been opened for editing in the overview panel. A listing of external parameter entities is shown in Figure 65.
Figure 65 Listing of External Parameter Entities
 
General Entities
DTDs provide facilities for defining some forms of content as well as document structure. Documents can include this predefined content by reference, allowing schema developers to centralize management of content as well as structure. Typically this approach is used to avoid search-and-replace on content that will be changing, or to include large chunks of 'boilerplate' content within a document.
In the General Entities tab of the advanced panel, the following types of entities can be defined:
The top panel is used to define internal general entities, while the bottom panel is used to define external general entities and unparsed entities.
Like the other panels, the rows begin with a selector button that can be used to select the entire row for cut, copy, paste, and clear operations. If there is an error in the declarations made in a row, the row selector button will turn red. The column between the selector and the entity name will contain a document icon if the declaration has been included from another file. If it came from another file, it cannot be edited, though it can be copied and pasted into the current file.
The name for an entity is entered and displayed in the Name column. (Entity names must begin with a letter and may contain numbers, underscores, dashes, and full stops -- typically periods).
Internal General Entities
Defining an internal general entity requires only the entry of a name and a value. The value must be plain text or well-formed XML - all start tags in the entity must have end tags and vice versa. Figure 66 illustrates the creation of two internal general entities.
Figure 66 Defining Internal General Entities
Documents using this schema may now include the content defined in the general entity area using entity references, which look like:
&entityName;
The parser strips out the entity references and replaces them with the value of the entity. For example, using the entities described in the figure above,
Our new &productName; (&productNum;) is the finest of its breed.
will become:
Our new Capital 8850 (CXY-8850) is the finest of its breed.
External General Entities
External general entities work very similarly, except that the value isn't given in the declaration. Instead, a reference to another document in your project is provided (either a full or relative path name), and the contents of the referenced document are used as the value for substitution. Like the value of an internal entity, all markup within the referenced file must be well-formed. Optionally, a public identifier (used in some SGML environments) may be provided. The notation column should be left blank for an external general entity. Figure 67 illustrates the creation of an external general entity.
Figure 67 Defining an External General Entity
External general entities are referenced from documents the same way that internal general entities are referenced -- using the &entityName; syntax. In this case, &play; would reference the XML document 'othello.xml' and include it in a document.
External Unparsed Entities
The last kind of entity that can be created in the general entities tab is the unparsed external entities. Unparsed entities reference non-XML content, like graphics files or data. Documents reference unparsed entities through the use of attributes of type ENTITY or ENTITIES. To create an unparsed entity, provide the same information as would be provided for an external general entity (name, system identifier, optional public identifier), but also provide a notation in the Notation column to identify the file type that is being referenced. This notation must be declared on the Notations tab. The 'myGraphic' unparsed entity shown below in Figure 68 is an example of an unparsed entity.
Figure 68 Defining an External Unparsed Entity
Notations
Notations allow you to describe a new data type or file type. The description involves a name for the type and a link to more information on the type or to programs that can process the type. For example, the notations declared in Figure 69 provide information on ISO8601 dates and times, and Java integers. Either could be used for a data type and will appear as an option in the type menus that appear in the elements panel and attributes panel.
Figure 69 Notations
Each notation is listed in a row of the panel. Information associated with each notation appears in columns across the panel and includes the following (from left to right).
Note: Use the Insert File Name button to browse for and select a file in your project containing the desired content.
Processing Instructions
Processing instructions are a relatively free-form way to include extra information about your schema for an application to use.
Each processing instruction is listed in a row of the panel. Information associated with each processing instruction appears in columns across the panel and includes the following (from left to right).
Schema Properties Panel
When selected by way of the Schema > View menu, the schema properties panel is displayed. The schema properties panel provides a count of the different type of components used to build the DTD. (This information is also found on the Statistics tab of the configuration panel).
Errors Panel
When selected by way of the Schema > View menu or upon clicking the Errors button on the toolbar, the errors panel appears between the active editing panel and the configuration panel. The errors panel displays errors found when a new DTD is loaded, as well as errors detected throughout the editing process.
The errors panel indicates the total number of errors and provides a list of errors and details about the errors in this panel. Clicking on the error message will take you to the source of the error.
Notes Panel
The raw declarations in your schemas are very useful for parsers processing your document, but are rarely sufficient for other humans who need to read and make sense of your schema. Adding notes helps those who use and maintain your schema to understand your schema designs, and can be a critical tool for keeping groups of developers working on the same or related schemas in sync.
The notes panel provides an area where you can add schema level documentation to your schema as well as document individual declarations and preview their source. When selected by way of the Schema > View menu, the notes panel appears between the active editing panel and the configuration panel.
Use the button in the upper right-hand corner of the notes panel to indicate whether you are interested in working with declaration-level notes (the default view) or notes about the schema as a whole. To view or edit notes for the schema as a whole, click Show Document. (The name of the DTD will appear in the upper left-hand corner of the panel.) To toggle back to the default, declaration-level view, click 'Show Selected Declaration'. (The the name of the declaration will appear in the upper left-hand corner of the panel.)
When the notes panel reflects the selected declaration, three tabs are available:
When the notes panel reflects the document as a whole, two tabs are available:
Table 35 Notes Panel
Source Panel
When selected by way of the Schema > View menu or upon clicking the Source button on the toolbar, the source panel becomes the primary panel for editing. The source panel allows you to edit the source code of your DTD directly. If you're comfortable with DTD syntax, editing your declarations directly may occasionally be useful or even convenient. Even if you don't want to edit your DTD directly, the source panel provides another way to examine your declarations.
To make the other panels reflect the changes you've made, click Reparse at the top of the panel. Any errors found upon reparse will be listed in the errors panel.

Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved