If your element has either element content or mixed content, its
content model is represented by a group node. You can add children elements
or another group to a group node, and specify how often, and in what manner
a group of elements will be available in an XML file associated with your
DTD.
The following instructions were written for the Resource
perspective, but they will also work in many other perspectives.
To
edit a group node, follow these steps:
- Open your DTD in the DTD editor.
- In the Outline view, expand the tree of the element you want to
work with.
- Click the group node you want to work with.
- In the Design view, select Sequence or Choice from
the Model Group list. This specifies whether
the group of elements are sorted in sequence or are available as a choice
in an XML file.
- Select the appropriate option from the Occurrence list
to indicate how often the group of elements can occur in an XML file associated
with this DTD.
- To add another existing element to a group as a child, right-click
the group node, click Add Element to Content Model,
and select it.
- You can also add a group to an existing group node, by right-clicking
the group note and clicking Add Group to Content Model
Note:The Occurrence option for the
group node only specifies how often the entire group of elements can occur
in an XML file. For each child element contained in the group, you can also
specify how often it can occur (that is, how often a child element can occur
is completely separate from how the often the group that contains it can occur).
Tip::
To change the order of elements listed below a group node, simply click the
element you want to move and drag it to the location you want it in.
Creating a group node that contains a list of small pets
The
following steps show you how to create a group node that contains a list of
small pets and explains how the choices you select affect how your group node
(and the elements it contains) can be used in any XML files based on your
DTD file:
- Create a new DTD called Pets.dtd and open it in
the DTD editor.
- In the Outline view, right-click your DTD file, and create a new element SmallPets.
Also create three more elements - Cats,Dogs,
and.Fish.
- Expand SmallPets and select the EMPTY content
model. Select Mixed Content from the Content
type list. This means your SmallPets element
can contain both other elements and character data.
- Your content model is now represented by a group node
. A #PCDATA
element (for character data) and new child element are automatically created
below it. Select the newChild and select Dogs in
the Content Model list.
- Right-click the group node and click Add Element to Content
Model. Select the new child node and select Cats in
the Content Model list.
- Repeat the previous step and select Fish in the Content
Model list.
- Now that you have created your list of small pets, you have to decide
if you want users to be able to select all of them or just one of them in
an XML file based on this Pets.dtd file. For example, you create a new XML
file called Pets.xml based on this DTD, and you create
a SmallPets element in it. If you selected Sequence as
the model group in the DTD file, then you can have all of the small pets ( Cats,
Dogs and Fish) in your SmallPets element
in the Pets.xml file. If, however, you selected Choice as
the model group, you can only have one animal listed in your SmallPets element
in the Pets.xml file. You can have Cats or Dogs or Fish, but you can only have one at a time.
- Now you have to decide how often this group of elements (the list of small
pets) can occur in an XML file associated with this DTD. You can specify that
it must appear only once (Just once), that it must
appear one or more times (One or more), that it does
not have to appear at all (Optional) or that it might
not be used at all or might be used any number of times (Zero or
more). Note: You can also specify how
often each child element can occur. How often a child element can occur is
completely separate from how the often the group that contains it can occur.
So, for example, you can specify that the SmallPets group
can occur Just once, but the Cats element can
appear several times (to do this, select the Cats element
and click One or more).
- The order in which you specify child elements in a group affects how they
can be used in any instances of the parent element in an XML file. For example,
if, in your DTD file, you had specified this: <!ELEMENT SmallPets
(Dogs+ , Cats+ , Fish)+>, any instances ofSmallPets in
your Pets.xml file must contain one or more instances
of Dogs followed by one or more instances of Cats,
followed by just one occurrence of Fish. You could
never have an occurrence of Fish after Dogs or Cats before Dogs.
- You can also add a group to an existing group node. Select the node, right-click
it and click Add Group to Content Model. You might
want to add a group node, if you decided you wanted to sort the animals by
breed into separate groups.