|
Home > Online Product Documentation > Table of Contents > Defining Elements in DTDs Defining Elements in DTDsYou can define an element in the Text or Tree tab. In the Text tab
In the
Text tab, you enter the text that defines your element and describes its structure. For example, to define a
When you define elements in the Text tab, you must know the syntax and keywords for what you want to define. This information is publicly available on the World Wide Web. Stylus Studio documentation does not include instructions for defining a DTD in the Text tab. For DTD information, see, http://www.w3.org/TR/REC-xml. In the Tree tab
When you use Stylus Studio, it is easier to define an element in the Tree tab. In the
Tree tab, you click
New Element Definition
1. Create the element by specifying its name. To do this, see
Defining Elements in the DTD Tree Tab, which is the first topic in this section.
2. Define the structure of the element by specifying modifiers, defining where raw data is allowed, and adding references to other elements. To help you do this, this section discusses the following topics:
Defining Elements in the DTD Tree TabIn the DTD editor, if the Tree view is not visible, click the Tree tab at the bottom of the window. To create an element in the Tree tab:
1. Click the
DTD node at the top of the tree.
2. In the tool bar on the left, click
New Element Definition
3. Type the name of the new element and press Enter. Stylus Studio displays the properties for the new element in the
Properties window. If the
Properties window is not visible, select
View > Properties from the Stylus Studio menu bar. For example, suppose you specified
title as the name of the new element. Your new element has the following properties:
4. To change the value of a property, double-click the current value. For information about the properties that each element can have, see
About Node Properties in DTDs.
After you create an element, you must define the structure of the contents of the element. The rest of the topics in this section provide information on how to define structure. Specifying That an Element Can Have an Attribute in DTDsIn the DTD Tree tab, to specify that an element can have an attribute:
1. Click the name of the element that you want to have an attribute.
2. In the menu bar on the left, click
New Attribute
3. Type the name of the attribute and press Enter.
Specifying That an Element is Required in DTDsYou specify that an element is required when you add a reference to that element in another element. In the Tree tab, to specify that an element is required:
1. Define the element that you want to be required. See
Defining Elements in the DTD Tree Tab.
2. Create the element that contains the element that you want to be required. This is the container element.
3. Click the container element name.
4. In the tool bar on the left, click
New Modifier
5. Double-click
Sequence.
6. If the required element can appear only once, skip this step. If the required element can appear more than once, click
New Modifier and double-click
One or More in the pop-up menu.
7. With the modifier highlighted, click
New Reference to Element
8. Enter the name of the element that you want this element to reference.
After you add a reference to an element, you might want to check the definition of the referenced element. To do this, right-click the reference. In the shortcut menu, click Go To Definition. Stylus Studio moves the focus to the definition of the referenced element. Example 1
For example, suppose the
The tree representation looks like this:
Example 2
It is also possible for an element to be required and for more than one to be allowed. Suppose the
The tree representation looks like this:
Specifying That an Element is Optional in DTDsYou specify that an element is optional when you add a reference to that element in another element. When an element is optional, it means that there can be one or none. If you want to specify that there can be none, one, or more, use the Zero or More modifier. See Specifying That Multiple Instances of An Element Are Allowed in DTDs. In the Tree tab, to specify that an element is optional:
1. Define the element that you want to be optional. See
Defining Elements in the DTD Tree Tab.
2. Create the element that contains the element that you want to be optional. This is the container element.
3. Click the container element name.
4. In the tool bar on the left, click
New Modifier
5. If the container element can contain only the optional element, skip this step. If the container element can contain more than one element, click
Sequence.
6. Click
New Modifier.
7. In the pop-up menu that appears, double-click
Optional.
8. In the tool bar on the left, click
New Reference to Element
After you add a reference to an element, you might want to check the definition of the referenced element. To do this, right-click the reference. In the shortcut menu, click Go To Definition. Stylus Studio moves the focus to the definition of the referenced element. Specifying That Multiple Instances of An Element Are Allowed in DTDsYou specify that multiple instances of an element are allowed when you add a reference to that element in another element. When multiple instances of an element are allowed, you specify that there can be either In the Tree tab, to specify that there can be multiple instances of an element:
1. Define the element that can appear multiple times. See
Defining Elements in the DTD Tree Tab.
2. Define the element that contains the element that can appear multiple times. This is the container element.
3. Click the container element name.
4. In the left tool bar, click
New Modifier
5. If the container element can contain only one type of element, skip this step. If the container element can contain more than one type of element, double-click
Sequence, and then click
New Modifier.
6. Double-click
Zero or More to allow the container element to contain zero, one, or more instances of an element. Or, double-click
One or More to allow the container element to contain one or more instances of an element.
7. In the left tool bar, click
New Reference to Element
After you add a reference to an element, you might want to check the definition of the referenced element. To do this, right-click the reference. In the shortcut menu, click Go To Definition. Stylus Studio moves the focus to the definition of the referenced element. Example 1Suppose there are some elements that can appear zero, one, or more times, and there are other elements that can appear one or more times. The tree representation for this might look like the following:
In this example, an instance document must contain these elements in the following order:
Example 2Suppose you want them in the following order:
In this case, the tree representation would look like this:
Specifying That An Element Can Contain One of a Group of Elements in DTDs
You might want to define an element that contains one element out of a group of elements. For example, you might want an
In the Tree tab, to define an element that contains one of a group of elements:
1. Define the elements that your new element can contain. See
Defining Elements in DTDs.
2. Define the element that you want to contain another element. This is the container element.
3. Click the container element name.
4. In the left tool bar, click
New Modifier
5. Double-click
Choice.
6. For each element in the group of elements from which one element can appear:
a. Click
New Reference to Element
b. Type the name of the element and press Enter.
After you add a reference to an element, you might want to check the definition of the referenced element. To do this, right-click the reference. In the shortcut menu, click Go To Definition. Stylus Studio moves the focus to the definition of the referenced element. When the XSLT processor validates an instance document against this DTD, it ensures that each instance of the new element you just defined contains exactly one of the referenced elements. Example
The tree representation for an
Specifying That an Element Can Contain One or More Elements in DTDsOften, you want an element to contain a sequence of elements. Some of these elements might be required, some might be optional, and some might be able to occur more than once. There might even be a group of elements in which only one can appear. In the Tree tab, to define an element that contains a sequence of elements:
1. Define the elements that you want your new element to contain. See
Defining Elements in DTDs.
2. Define the element that contains the sequence of elements. This is the container element.
3. Click the container element name.
4. In the left tool bar, click
New Modifier
5. Double-click
Sequence.
6. To add required elements to the container element, click
New Reference to Element
At this point, you can add Specifying ModifiersThe procedure is the same for these modifiers. The only difference is the modifier you select. For example, following are the instructions for adding optional elements:
1. In the DTD editor, click the
Sequence modifier.
2. In the left tool bar, click
New Modifier.
3. Double-click
Optional.
4. For each optional element, click
New Reference to Element and enter the name of the optional element. This works only if you want all optional elements to be consecutive. If you want optional elements to be interspersed with required elements or elements that can appear one or more times, you must perform steps 1 through 4 for each element.
Modifying the OrderIn an instance document, the contained elements must appear in the order in which they are specified in the DTD. To modify the order:
1. Click the modifier for the element you want to move.
2. Click the up or down arrow repeatedly until the element is where you want it to be.
To move a required element that can appear only once, click its name and then use the up and down arrows. Alternative: Right-click the item you want to move. Select Move Up or Move Down from the shortcut menu. Specifying That an Element Can Contain Data in DTDsTo specify that an element can contain raw data, you must first define the element. See Defining Elements in the DTD Tree Tab. In the Tree tab, to specify that an element can contain data:
1. Click the element you want to contain data.
2. In the left tool bar, click
New Modifier
3. Double-click
Zero or More.
4. In the left tool bar, click
Add $PCDATA
Moving, Renaming, and Deleting Elements in DTDs
To move an element definition or a reference to an element, in the
Tree tab, click the name of the element or the modifier for the reference. Then click
Move Up
Alternative: Right-click the item you want to move. Select Move Up or Move Down from the shortcut menu that appears. RenameTo rename an element or attribute, right-click it and select Rename from the shortcut menu that appears. Type the new name and press Enter.
Alternative
: Click
Change Name
DeleteTo delete a node in the DTD, right-click the node you want to delete. In the shortcut menu that appears, click Delete.
Alternative
: Click
Delete Node
|

Cart

