Elements are fundamental building blocks in XML. Element
declarations provide value constraints, and a description that can be used
for validation, as well as establishing constraining relationships between
related elements and attributes, and controlling substitution of elements.
The following instructions were written for the Resource
perspective, but they will also work in many other perspectives.
To
add an element, follow these steps:
- In the Outline view, right-click the content
model you want to work with and click Add Element.
- In the Properties view, type a new name for the
element in the Name field.
- Specify its type information by clicking the Browse button
and selecting the appropriate type. The Set Type dialog
lists all built-in and user-defined types currently available. You can change
the Scope of the list by selecting
one of the following options:
- Workspace. Lists all of the types
available in your workspace.
- Enclosing Project. Lists all
of the types available in the project that contains your file.
- (Default) Current Resource. List
all of the types available in your current file.
- (Optional) Select the appropriate value in the MinOccurs field. This is the number of
times the element may appear. If you want the element to be optional, select 0. Otherwise, select 1.
- (Optional) Select the appropriate value in the MaxOccurs field. This is the maximum number
of times the element may appear. You can select unbounded to
indicate there is no maximum number of occurrences.
-
(Optional) Click the
Other tab.
In this page, you can specify the following various values for the element:
- block. This field determines
whether the element may be replaced by an element derived from it.
- fixed/default. Click the Browse button
and select the Fixed or
Default radio button and specify an
appropriate value. If you select Fixed, the element has
a fixed value, which cannot be changed. If you select Default,
the element has a default value.
- form. Use this field to indicate
if the appearance of this element in an instance of the XML schema (that
is, an XML file associated with the XML schema) must be qualified by a
namespace.
- maxOccurs. This is the minimum
number of times the element can appear in an instance document. You can
specify this option here or in the General page.
- minOccurs. This is the maximum
number of times the element can appear in an instance document. You can
specify this option here or in the General page.
- nillable. Select true
if you do not want the element to be able to have any child elements,
only attributes.
- Click the Attributes tab. You
can use this page to add attributes, attribute references, attributes group
references, and any attributes to your element.
- An attribute associates an attribute name with
a specific type and value. To add an attribute, right-click in the Attributes
page, and click Add Attribute. You
can specify the following values for an attribute
- fixed/default. Click the Browse button
and select the Fixed or Default radio button and specify an appropriate
value. If you select Fixed, the attribute has a fixed value, which
cannot be changed. If you select Default, the attribute has a default
value.
- form. Use this field to indicate
if the appearance of this attribute in an instance of the XML schema must
be qualified by a namespace.
- name. Enter the name of the attribute.
- type. Click the Browse button
and select
the type of the attribute.
- use. This field indicates how an
attribute may be used in an instance document. If you select optional,
the attribute may appear once, but it does not have to. If you select required,
the attribute must appear once. If you select prohibited, the attribute
must not appear. Note: If you selected the Default radio
button, you must select optional in this field, otherwise the default
value will not be valid.
- An attribute reference provides a reference to
a global attribute. To add an attribute reference, right-click in the Attributes
page, and click Add Attribute Ref. A
declaration that references a global attribute enables the referenced attribute
to appear in the instance document in the context of the referencing declaration.
The menu option to add an attribute reference only appears if there are global
attributes defined elsewhere in the document.
- Select the reference, then select the global attribute you want
it to reference from the ref drop down
list.
- An attribute group reference provides a reference
to an attribute group. To add an attribute group reference, right-click in
the Attributes page, and click Add Attribute Group
Ref. A declaration that references an attribute group enables
the referenced attribute group to appear in the instance document in the context
of the referencing declaration. The menu option to add an attribute group
reference only appears if there are attribute groups defined elsewhere in
the document.
- Select the reference, then select the attribute group you want it
to reference from the ref drop down
list.
- An any element enables
element content according to namespaces, and the corresponding any attribute
element enables attributes to appear in elements. To add an any attribute,
right-click in the Attributes page and click Add
Any Attribute. You can specify the following values for
an any attribute:
- For a namespace value, you can select ##any (this
allows any well-formed XML from any namespace), ##local (this allows
any well-formed XML that is not declared to be in a namespace, ##other (this
allows any well-formed XML that is not from the target namespace of the type
being defined) or ##targetNamespace (which is shorthand for the target
namespace of the type being defined).
- For a processContents value, you
can select skip (the XML processor will not validate the attribute
content at all), lax (the XML processor will validate the attribute
content as much as it can), or strict (the XML processor will validate
all the attribute content).
- Click the Documentation tab
if you want to provide any information about this element. The Documentation page is used for human readable material,
such as a description, and the App Info page
can be used to provide information for applications.
You can add a content model to an element, which
is the representation of any data that may be contained inside the element.
For more information about working with content models, refer to the related
tasks.