2 ELEMENTS, ATTRIBUTES and ENTiTiES

This chapter discusses elements, attributes and entities and how to work with them in XML Pro. Elements are the foundations of XML documents. Attributes and entities are designed to further describe an element. XML Pro has features designed to make creating, deleting and managing of elements simple. Two of them are the Element Wizard and the Element Palette.


2.1 Element Wizard

Element Wizard

Figure 2-1 Element Wizard

Use the Element Wizard to create and remove element types for inclusion into the current document. When used in conjunction with a DTD, the Element Wizard only displays elements defined by the DTD, and does not allow elements to be removed.

If the DTD does allow creating new elements for the document, the Element Wizard can be used to create (and remove) new element types for it.

The Wizard contains three components:


2.1.1 Creating a New Element Using Element Wizard

Use the Element Wizard to create new Element types for your document. Follow these steps:

  1. Launch the Element Wizard from the Toolbar or Tools menu.
  2. Enter the element name in the New Element Name field. Element names are case sensitive; keep this in mind when creating new element types.
  3. Click on the Add button to create the new element type.

2.1.2 Deleting an Existing Element Type Using Element Wizard

To delete an element type:

  1. Select the Element type to be deleted from the list of Elements shown.
  2. Click the Remove button. Removing an Element from the Element Wizard removes it from your document entirely, including any information that is currently defined in existing elements. Before the element is removed, you will be prompted on screen to confirm that you want to remove the Element before proceeding. Once you click the OK button, the Element type, and any instances of it in your document are removed.
  3. Click the Close button to close the Wizard and return to your document.


[Top of Page]
[back to TOC]


Element Palette

2.2 The Element Palette

The Element Palette is a floating window that lists all available element types for the current open document.


2.2.1 inserting Elements Using the Element Palette

To insert an Element listed in the Element Palette into the current document, follow these steps:

  1. Select the insertion point for the new element in the document.
  2. Select the element type you want to add, and click the insert button. The new element is now added to your document.

If you are working with a DTD, and have selected the Available Elements Constrained by DTD option, elements shown in the Element Palette will change, depending on where in the document you are trying to insert the new element.



2.2.2 Sorting Elements

Elements displayed in the Element Palette are sorted in alphabetical order. if you have elements that are defined in a DTD, and then you create new elements, element types defined within the DTD will be displayed first, sorted alphabetically. Following the DTD defined elements will be any custom elements, grouped together and also sorted alphabetically.



[Top of Page]
[back to TOC]

2.3 Elements in the Document

Besides the Element Wizard and the Element Palette, XML Pro has other ways to insert, delete, and or move elements. While you must use the Element Wizard to create and remove element types, you can add individual instances of each element directly to the document tree.


[Top of Page]
[back to TOC]

2.4 inserting Elements

Elements can be inserted using the Element Palette, or by inserting them from directly within the document tree view (the window displaying the document on screen). To insert an element within the tree:

  1. Right click on the insertion point within the tree view.
  2. Select the Add Element sub-menu from the Pop-up menu (which displays by clicking your right mouse button), and then highlight the element you wish to insert.
  3. Release the mouse button, and the new element is inserted.

NOTE: The Add Element sub-menu is limited to displaying 15 elements. if your document contains more then 15, you will need to use the Element Palette to display all available element types.


[Top of Page]
[back to TOC]

2.5 Deleting Elements

Element types can only be removed by using the Element Wizard. Single occurrences of an element within a document can be deleted in one of two ways:

  1. Select the element to be deleted within the document tree view.
  2. Select Delete Element from the Tools menu.

or


[Top of Page]
[back to TOC]

2.6 Moving Elements

Elements shown in the document tree view can be repositioned in one of three ways:

  1. Right click on the element to be moved, and select Move Up or Move Down from the Pop-up menu.
  2. Select the element to be moved, and then choose Move Element Up or Move Element Down from the Tools Menu.
  3. Select the element to be moved, and use the up and down arrows on the toolbar to reposition the element.

[Top of Page]
[back to TOC]

2.7 Attributes

Attributes let you further customize elements to provide more information about them.


[Top of Page]
[back to TOC]

2.8 Attribute Wizard

The Attribute Wizard assigns attributes to elements, and also removes attributes from them.

Attribute Wizard

Figure 2.2 Attribute Wizard

This Wizard contains three components:

2.8.1 Creating New Attributes

Follow these steps to create a new attribute for an element type:

  1. Launch the Attribute Wizard.
  2. Select the element type you want to add the attribute to.
  3. Enter the attribute name in the New Attribute Name field. Attribute names are case sensitive, so type will be treated differently from type.
  4. Click Add, and the new attribute type appears in the Attributes list on the right. This attribute is now available for all elements of the selected type, and will appear in the Attributes Pane within the Editor.


2.8.2 Deleting Existing Attributes

Follow these steps to delete an exiting attribute type from an element:

  1. Launch the Attribute Wizard.
  2. Select the element from the Elements list, and then select the Attribute you wish to remove from the Attribute list.
  3. Click Remove to remove the attribute. You are prompted to confirm that you want to remove the attribute type. Removing the attribute type will delete all occurrences of the attribute from your document, including any values that might be assigned to the attribute. Once the attribute is removed, old values will be lost. if you do want to remove the attribute, select "OK" and it is removed.


2.8.3 Attributes with DTD's

When you are working with a document that has an Document Type Definition (DTD) associated with it, attributes for elements defined within the DTD cannot be modified via the Attribute Wizard. This is because of the constraints placed on it by the DTD.

2.8.4 Attributes in the Document

When you are editing a document in XML Pro, and you click on an element in the tree view that has an assigned attribute, the attribute appears in the Attribute Pane of the Editor.

Attribute Pane

Figure 2-3. Attribute Pane

From the Attribute Pane, you can enter, delete, or edit the values that have been assigned to element attributes in your document. You may also use the cut, copy, and paste editing features within the Attribute Pane when working with attribute values.


2.8.5 Assigning Values to Attributes

To assign a value to an attribute, follow these steps:

  1. Click on the element with the attribute. The attribute appears in the Attribute Pane.
  2. Enter a value for the attribute in the text field next to the attribute name.

NOTE: There is no confirmation button in the Attribute Pane. Once you have entered a value, if you select another element, the value is committed to memory. if the attribute is specified in the DTD as enumeration, the fixed choices will be presented within a drop-down list box.


2.8.6 How Attributes are Written

When you create attributes for an element, the attribute always appears in the Attribute Pane when that element is selected in the tree view.

However, you do not need to assign a value to all instances of that attribute in all elements. Only attributes that have values assigned are written to the final XML Code. This keeps your code from getting "empty attributes" which are not necessary to specify. To preview what attribute values are being written, use the View XML feature in the Tools Menu.


2.8.7 Viewing Attributes in Document Tree

XML Pro displays element attributes in the Attribute Pane, when an element is selected. To view all attributes for all elements within the tree view, select the View Attributes in Tree option from the Options menu. When selected, this option displays an element's attributes adjacent to the element in the document tree view.


[Top of Page]
[back to TOC]

2.9 Entities

Entities provide another way to customize an element in an XML document. Because Entities are defined within a document's DTD, XML Pro does not have a way to create or remove actual entities. However, you can list the Entities that are available to a document, and insert defined Entities into a document.

Entity Palette

2.9.1 The Entity Palette

The Entity Palette is a separate floating window that can be hidden or shown by selecting the Show Entity Palette option, found in the Options Menu. The window displays a list of the Entities that have been defined in the DTD, as shown on the left.

The Entity Palette can then be used to see the available Entities, and to insert them into the document.


[Top of Page]
[back to TOC]

2.10 Adding an Entity

There are two ways to add an entity to the current document:

  1. Select the desired entity from the Entity Palette after selecting the insertion point in the document, and click insert.
  2. Right click on the desired item you wish to insert the Entity into, and select Add Entity from the Pop-up Menu. Under the Add Entity sub-menu (shown on the next page), you will see another listing of the available Entities. Select the entity you wish to add and release the mouse. Only the first 15 entities are available on the sub-menu.
Add Entity Sub-menu

Figure 2-4. Add Entity Sub-menu


[Top of Page]
[back to TOC]

2.11 Removing an Entity

There are two ways to remove an entity from the current document:

  1. 1. Right click on the Entity you wish to remove, and select Delete.
  2. 2. Select the Entity you wish to remove, and select Delete Element from the Tools menu. This also deletes the Entity instance from the document.

These methods do not affect the Entity's availability in the Entity Palette, because Entities are defined within the DTD.


[Top of Page]
[back to TOC]