![]() |
| Previous Top Next |
Editing XML Documents |
XMLSpy offers some specialized XML text editing features:
Syntax coloring is applied according to XML node kind, that is, depending on whether the XML node is an element, attribute, content, CDATA section, comment, or processing instruction. The text properties of these XML node kinds can be set in the Text Fonts tab of the Options dialog (Tools | Options).
Start-tag and end-tag matching
When you place the cursor inside a start or end tag of an XML element, pressing Ctrl+E highlights the other member of the pair. Pressing Ctrl+E repeatedly enables you to switch between the start and end tags. This is another aid to locating the start and end tags of an XML element.
If you are working with an XML document based on a DTD or XML Schema, XMLSpy provides you with various intelligent editing capabilities in Text View. These allow you to quickly insert the correct element, attribute, or attribute value according to the content model defined for the element you are currently editing. For example, when you start typing the start tag of an element, the names of all the elements allowed by the schema at this point are shown in a pop-up (screenshot below). Selecting the required element name and pressing Enter inserts that element name in the start tag.

The popup window also appears in the following cases:
| • | If you press the space bar when the cursor is between an element's tags and if an attribute is defined for that element. The popup will contain all available attributes. |
| • | When the cursor is within the double-quotes delimiting an attribute value that has enumerated values. The popup will contain the enumerated values. |
| • | When you type </ (which signifies the start of a closing tag), the name of the element to be closed appears in the popup. |
Editing in Text View can easily result in XML documents that are not well-formed. For example, closing tags may be missing, mis-spelled, or structurally mismatched. XMLSpy automatically completes the start and end tags of elements, as well as inserts all required attributes as soon as you finish entering the element name on your keyboard. The cursor is also automatically positioned between the start and end tags of the element, so that you can immediately continue to add child elements or contents: <img src="" alt=""> </img>
XMLSpy makes use of the XML rules for well-formedness and validity to support auto-completion. The information about the structure of the document is obtained from the schema on which the XML document is based. Auto-completion uses not only information about the structure of the document, but also the values stored in the document. For example, enumerations and schema annotations in an XML Schema are actively used by the Auto-Completion feature. If, in the schema, values are enumerated for a particular node, then those enumerations will be displayed as auto-completion options when that node comes to be edited in the XML document. Similarly, if, for a node, annotations exist in the schema, then these annotations are displayed when the node name is being typed in the document (screenshot below). (First (given) name of person is the schema annotation of the First element.)

Auto-completion can be switched on and off in the Editing tab of the Options dialog (Tools | Options | Editing).
Drag-and-Drop and Context Menus
You can also use drag-and-drop to move a text block to a new location, as well as right-click to directly access frequently used editing commands (such as Cut, Copy, Paste, Delete, Send by Mail, and Go to line/char) in a context menu.
You can use the Find and Replace commands to quickly locate and change text. These commands also take regular expressions as input, thereby giving you powerful search capabilities. (See Edit | Find for details.)
XMLSpy offers unlimited levels of Undo and Redo for all editing operations.
You can zoom in and out of Text View by scrolling (with the scroll-wheel of the mouse) while keeping the Ctrl key pressed. This enables you to magnify and reduce the size of text in Text View.
Text in an XML document can be commented out using the XML start-comment and end-comment delimiters, respectively <!-- and -->. In XMLSpy, these comment delimiters can be easily inserted using the Edit | Comment In/Out menu command.
To comment out a block of text, select the text to be commented out and then select the command Comment In/Out, either from the Edit menu or the context menu that you get on right-clicking the selected text. The commented text will be grayed out (see screenshot below).

To uncomment a commented block of text, select the commented block excluding the comment delimiters, and select the command Comment In/Out, either from the Edit menu or the context menu that you get on right-clicking the selected text. The comment delimiters will be removed and the text will no longer be grayed out.
|