Elements are specific components of a document that are surrounded by markup. Once you create an XML document, you can insert and edit elements using a variety of methods.
In this section, you'll learn about
inserting elements
editing elements
applying rules to elements
editing element rules
associating elements
editing element attributes
Inserting elements
You can insert new elements manually or automatically. Automatically inserting elements is useful when you are creating a new XML document because the required elements are quickly inserted in the proper order.
You can also insert new elements that are not defined in the DTD. Upon document validation, you will be warned when elements are not defined. Undefined elements are not validated.
You can specify the root element of an XML document. Validation starts from the root element in an active XML document. If you do not specify a root element, the root element defined in the DTDeclaration is used. You can specify a root element for every XML document saved in a separate file.
You can also create an element rule that will display text as part of the element formatting. For example, you can create an element rule that will display the name of the document author whenever you insert the Author element into the XML document.
You also define a hierarchy, you set conditions that an element must meet in order for layout codes to be applied to the element. For example, if you specified the element <PS> as the parent of <PARA> in the Element rule dialog box, the layout codes would be applied only to <PARA> elements that occurred within <PS> elements.
To manually insert elements
1 In the WordPerfect XML Editor, click Insert Elements.
2 Disable the Auto-insert check box.
3 Enable one of the following options:
Valid elements-displays only the valid elements of the associated DTD
All elements-displays all the elements contained in the associated DTD
4 Choose an element from the All elements list.
If you want to view the valid optional elements in an SGML document, enable the Inclusions check box.
5 Click Insert.
You can also
Display the Edit attributes dialog box whenever you insert a tag with attributes into the XML document Click Options Always prompt for attributes
Never display the Edit attributes dialog box Click Options Never prompt for attributes
Display the Edit attributes dialog box when you insert a tag containing required attributes into the XML document. Click Options Prompt when attributes required
Tip
You can also choose an element in the All elements list by double-clicking the element.
To automatically insert elements
1 In the WordPerfect XML Editor, click Insert Elements.
2 Enable the Auto-insert check box.
3 Enable one of the following options:
Valid elements-displays only the valid elements in the XML document
All elements-displays all the elements contained in the associated template
4 Choose an element from the All elements list.
5 Click Insert.
WordPerfect inserts all required tags and their siblings into the document.
Tips
You can also choose an element in the All elements list by double-clicking the element.
When you use Auto-insert, the Enter key no longer inserts hard returns. You must close the Elements dialog box or disable the Auto-insert check box to use the Enter key to insert hard returns. You can also insert hard returns automatically by creating a draft template with a defined layout that simply inserts a new line after each end tag (or after both start and end tags, if you prefer). Use this draft template file with the Auto-insert check box enabled to automatically insert hard returns at strategic points throughout a document without pressing Enter.
To insert new elements not defined in the DTD
1 In the WordPerfect XML Editor, open or create an XML document.
2 Click Insert Element.
3 Type the name of the element in the Element box.
If you want to include the associated attributes of the element, you must also type the element attribute name and values. For example, type car color="red" where car is the element name, color is the attribute name and red is the attribute value.
Tips
You can insert new elements by typing the name of the element and associated attributes in the Valid elements box on the property bar and pressing Enter.
You can also open the Element dialog box by using the Ctrl + E shortcut keys.
To specify the root element
1 In the WordPerfect XML Editor, open or create an XML document.
2 Click XML Root element.
3 Choose an element from the Root element list.
4 Click Select.
Tip
You can return to the default root element for the selected document type by clicking XML Root element Original.
To insert text with element content
1 In the WordPerfect XML Project Designer, open or create an XML project.
2 Choose an element in the Edit rule list.
3 Click Edit Edit rule.
4 Click Display Text.
5 Type the text in the Text box.
The text will display when the selected element is inserted into the XML document.
Tips
You can also choose an element by clicking the Elements button on the property bar.
To define the element hierarchy
1 In the WordPerfect XML Project Designer, open or create an XML project.
2 Choose an element in the Edit rule list.
3 Click Edit Edit rule.
4 Click Hierarchy.
5 Enable one of the following options:
Show parents only-displays only the valid parent elements of the selected element
Show all elements-displays all the elements defined in the DTD
6 Choose an element from the Element and parents selected list.
7 Choose a parent element from the Element parents list.
8 Click Add parent.
Notes
If you choose the Show all elements option, the WordPerfect XML Project Designer will not validate the elements you insert as parent elements. For example, the WordPerfect XML Project Designer will allow you to insert <BODY> as a parent element to <MEMO> even if it is an invalid element order.
If a default attribute value is defined in the DTD, WordPerfect highlights the default attribute value displayed in the Element attributes selected box. Otherwise, the first attribute value in the list is highlighted.
Tips
You can choose an element in the Element parents list by double-clicking the element.
You can edit the element hierarchy by choosing an element in the Element Rule list and clicking Edit Edit hierarchy.
Editing elements
Once you create an XML document, you can edit it using a variety of methods. You can edit elements, copy element rules from one element to another, and assign user-friendly names known as aliases to the elements defined in the DTD you are using. The alias names you create are saved in a WordPerfect template.
You can also edit an element by performing an automatic search and replace for tags, codes, text, or attributes associated with an element. You can locate elements by searching for their tags. WordPerfect searches for the start or end tag of the element closest to the cursor.
To rename an element
1 In the WordPerfect XML Editor, open or create an XML document.
2 In the XML document, position the cursor after the start tag of an element.
3 Click Insert Element edit.
4 In the Element box, type a new name for the element.
For example, Salutation title="Miss" surname="Smith"
Note
In an SGML document, you can only rename an element if the new name is defined in the DTD.
To copy an element
1 In the WordPerfect XML Project Designer, open or create an XML project.
2 Choose an element from the Element rule list.
3 Click Edit Copy rule.
Tip
You can also copy an element by selecting an element in the Edit rule list and clicking the Copy Rule button on the property bar.
To create an alias name for an element
1 In the WordPerfect XML Project Designer, open or create an XML project.
2 Choose an element from the Edit rule list.
3 Click Tools Alias.
4 Choose an element from the Associations list.
5 Type an alias name for the selected element in the Alias box
6 Click in the Associations list.
The alias name is added to the list of associations.
Notes
Alias names are defined once for each template, even if the template contains multiple layouts.
The alias names you assign for elements will display in place of the element names in the application bar, reveal codes, error messages, and XML documents. When saving an XML document, the alias names are converted to the actual XML element name.
To find and replace text within elements
1 In the WordPerfect XML Editor, open or create an XML document.
2 Click Edit Find and replace.
3 Type the text in the Find box.
4 Type the replacement text in the Replace with box.
5 Click Match Elements.
6 Enable the Use match element conditions to limit the find check box.
7 Enable one of the following buttons:
Listed element order-searches for text within elements in the order specified in the Elements to search in boxes
Any listed element-searches for text within all elements
8 Choose an element from the Elements to search in box.
If you want to exclude an element from the search, choose an element from the Elements to ignore box.
Applying rules to elements
Applying rules to elements lets you edit elements and attributes in an XML document. You can rename an element and apply a rule to another element. Elements are specific components of a document that are identified and marked with XML tags.
Attributes qualify the formatting and content of an element. You can define attributes to specify what the content of an element should be, to specify justification definitions, and to specify formats such as font style. For example, an attribute could specify that the content of the element status be either public or confidential. You can also rename elements or copy an element rule from one element to another.
To apply a rule to another element
1 In the WordPerfect XML Project Designer, open or create an XML project.
2 Choose an element from the Element rule list.
3 Click Edit Rename rule.
4 Choose an element from the list.
Tip
You can also rename an element by clicking the Rename rule button.
To revert an element rule
1 In the WordPerfect XML Project Designer, open or create an XML project.
2 Choose an element in the Edit rule list.
3 Click Edit Edit rule.
4 Click in the Rule entry for end tag (before revert) box.
5 Click Insert Revert.
6 Choose the feature you want to revert from the Function list.
Note
The Function list displays only the features that you can revert with the exception of on/off functions. On/off functions do not display in the Function list but can be reverted.
Tip
You can also choose an element by clicking the Elements button on the property bar.
Editing element rules
Rules are applied to the selected element in the order that they appear in the rule entry boxes of the WordPerfect XML Project Designer. You can change the order of element rules, edit element rules, delete element rules that are no longer required, and restore up to ten element rules that you have deleted.
To edit element rules
1 In the WordPerfect XML Project Designer, open or create an XML project.
2 Choose an element from the Element rule list.
3 Click Edit Edit rule.
4 Choose the code you want to edit from one of the following boxes:
Rule entry for start tag Displays all existing formatting rules for the selected element that take effect at the start tag. Lets you create a hierarchy or choose a rule to edit, move, or delete.
Rule entry for end tag (before revert) Displays all existing formatting rules for the selected element that take effect at the end tag. Lets you create a hierarchy or choose a rule to edit, move, or delete.
Rule entry for end tag (after revert) Displays all formatting rules for the selected element that take effect at the end tag after a revert (return to a previous setting). Lets you create a hierarchy or choose a rule to edit, move, or delete.
Tip
You can also edit an element rule by double-clicking on the rule and clicking the Edit rule button.
To move element rules
1 In the WordPerfect XML Project Designer, open or create an XML project.
2 Choose an element from the Element rule list.
3 Click Edit Edit rule.
4 Choose the rule you want to move from one of the following boxes:
Rule entry for start tag Displays all existing formatting rules for the selected element that take effect at the start tag. Lets you create a hierarchy or choose a rule to edit, move, or delete.
Rule entry for end tag (before revert) Displays all existing formatting rules for the selected element that take effect at the end tag. Lets you create a hierarchy or choose a rule to edit, move, or delete.
Rule entry for end tag (after revert) Displays all formatting rules for the selected element that take effect at the end tag after a revert (return to a previous setting). Lets you create a hierarchy or choose a rule to edit, move, or delete.
5 Choose one of the following options:
Move up-moves the code up one place in the list
Move down-moves the code down one place in the list
To delete element rules
1 Choose a rule from one of the following boxes:
Rule entry for start tag Displays all existing formatting rules for the selected element that take effect at the start tag. Lets you create a hierarchy or choose a rule to edit, move, or delete.
Rule entry for end tag (before revert) Displays all existing formatting rules for the selected element that take effect at the end tag. Lets you create a hierarchy or choose a rule to edit, move, or delete.
Rule entry for end tag (after revert) Displays all formatting rules for the selected element that take effect at the end tag after a revert (return to a previous setting). Lets you create a hierarchy or choose a rule to edit, move, or delete.
2 Click Delete entry.
Tip
You can also delete an element rule by choosing an element from the Edit rule list and clicking Edit Delete rule.
To restore an element rule
In the WordPerfect XML Project Designer, click Edit Undelete rule.
Tip
You can also restore your last delete by clicking the Undelete rule button on the property bar.
Associating elements
When you associate a feature or macro with an element that meets the specified conditions, WordPerfect opens the associated feature or runs the macro when you insert the element. For example, if you select a <BKGROUND> element and then associate it with a Watermark, WordPerfect automatically opens the Watermark dialog box when you insert a <BKGROUND> tag in the document.
To associate a WordPerfect feature with an element
1 In the WordPerfect XML Project Designer, open or create an XML project.
2 Choose an element with attributes from the Element rule list.
3 Click Edit Edit rule.
4 Click Edit Element associate.
5 Choose an association type from the Association list.
6 Choose the element from the Element list.
To associate a macro with an element
1 In the WordPerfect XML Project Designer, open or create an XML project.
2 Choose an element with attributes from the Element rule list.
3 Click the Browse button next to the Macro box and choose the drive and folder of the macro.
Editing element attributes
You can assign and display an attribute value. Attributes qualify the appearance or content of an element and are defined in the DTD. You cannot add or delete attributes using WordPerfect. You can, however, use attributes to define the context in which an element rule is used. For example, you want the class of document to appear on the title page of all documents that are confidential. You add an attribute constraint (or value) to an element called status that specifies that the content of status can be either "public" or "confidential". When the content is confidential, you display the document status on the title page.
You can edit elements and attributes in an XML document. You can rename an element, apply a rule to another element, and edit or delete an element attribute. Elements are specific components of a document that are identified and marked with SGML or XML tags.
You can define attributes to specify what the content of an element should be, justification definitions, and formats such as font style. For example, an attribute could specify that the content of the element status be either public or confidential. You can also rename elements or copy an element rule from one element to another.
You can display the XML Tree to locate the element you want to edit. The XML Tree window displays a structured view of all document elements and attributes
To display element attribute values
1 In the WordPerfect XML Project Designer, open or create an XML project.
2 Double-click an element with attributes in the Edit rule list.
3 Click Display Attribute value.
4 Choose an element attribute from the Attribute list.
Note
If you want to display the attribute value of a parent for a selected element, you must first add the parent element in the Hierarchy and attributes dialog box. For example, if a DTD contains a <BOOK> element with an attribute value of "Volume X" and also contains a <CHAPTER> element, you can display the attribute value for <BOOK>, "Volume X", with the <CHAPTER> element. To do so, you would first use the Hierarchy and attributes feature to specify <BOOK> as a parent element of <CHAPTER>.
Tip
You can also choose an element by clicking the Elements button on the property bar.
To add an element attribute constraint
1 In the WordPerfect XML Project Designer, open or create an XML project.
2 Choose an element with attributes in the Edit rule list.
3 Click Edit Edit rule.
4 Click Hierarchy.
5 Choose an attribute from the Element attributes list.
6 Click Add attribute.
7 Choose a value for List, Entity, or Entities type attributes from the Value list.
If the attribute is not a List, Entity, or Entities type, type a value in the Value list and click Select.
Tip
You can also add an element by clicking an element in the Element rule list, and clicking Edit Edit hierarchy.
You can also choose an element by clicking the Elements button on the property bar.
To delete an element attribute constraint
1 In the WordPerfect XML Editor, open or create an XML document.
2 Click Insert Edit attributes.
3 Choose an attribute name from the Attributes list.
4 Click Delete attribute.
Note
The default attribute value defined in the DTD is used when no attribute value is specified for an element.
To edit an element attribute
1 In the WordPerfect XML Editor, open or create an XML document.
2 In the XML document, position the cursor after an element.
3 Click Insert Edit attributes.
4 Choose an attribute name from the Attributes list.
5 Click Edit value.
6 Choose a value for List, Entity, or Entities type attributes from the Value list.
If the attribute is not a List, Entity, or Entities type, type a value in the Value list and click Select.