facebook

MyEclipse XML Editor


1. XML Editing in MyEclipse

This document covers some of the functions available in the MyEclipse XML Editor. The MyEclipse XML editor includes advanced XML editing such as:

  • Syntax highlighting
  • Tag and attribute content-assist
  • Real-time validation (as you type)
  • Source, Design and Outline views of the document’s contents
  • Document formatting
  • Content-assist templates


2. Editing Modes

Editing XML using the MyEclipse XML editor can be done in two different modes: Design Mode and Source Mode. You switch between the two modes using the tabs at the bottom of the editor:

xml_switch_modes
Mode tabs

Switching between the two modes can be done any time as they are kept in sync with each other automatically.


2.1 XML Design Mode

When you first open an XML document in Design Mode, it looks something like this:

xml_design_mode
XML Design view

In Design mode, the contents of your XML document are displayed as a detailed outline. Along the left column, you see the tags that make up your document, and in the second column you see the values for those tags. You can double-click any of the values in the second column and edit them directly in this view, making it very easy to visually understand and edit an XML file without worrying about syntax.

Another nice feature of using the Design Mode is that you can add, remove, and edit tags visually and the designer provides you with only the options that properly adhere to the DTD or Schema referenced by the document. More specifically, the design won’t allow you to insert an invalid tag.

As an example, say you want to add a new child element to the shipto element in the XML document. Right-click the element, and select Add Child>New Element from the menu.

add_child
Adding a description to the context-param

Double-click an element’s content to edit. Editing any of the tag values or adding/removing child tags can be done in this fashion without needing to switch to the Source mode for editing. However, editing the source directly can be faster sometimes, and some developers prefer it.

inline_element_edit
In-line editing of an element value


2.2 XML Source Mode

While editing XML documents in design mode can certainly be easier at times and save you from making errors, at times it’s necessary (or preferred) to work directly with the source code. If that is the case, MyEclipse’s XML editor provides extensive source-editing features.

When you first open your XML document to edit it, it looks something like this:

xml_source_mode
XML Source view

You’ll notice the collection of views available to help you edit your document. The Source view is on the left for editing code, you have a simplified Outline view on the top right, and a Properties view on the bottom right

Note: Due to the flexible nature of laying out MyEclipse’s views, you can move them anywhere you like and your workspace might not look identical to the image above.

All these views stay in sync with the file you are editing as you work. As you click inside a tag, the Properties view displays the values for that tag.

The Outline view provides very similar visual-editing functions as the Design mode if you’d prefer to use it.

xml_source_outline
Using the Outline view

If you edit the XML source using the editor, you have some very nice assistance as you work. For example, misspelling a tag or attribute name is marked immediately as an error (checked against the DTD or schema referenced by the doc).


XML errors are marked for you

To help make editing easier, content assist is available for tags and attributes. Content assist suggests legal completion options to you based on the position of your cursor.


Using content assist

A lot of the functions provided by the MyEclipse XML editor depend on your document correctly referencing a DTD or schema so the editing tools can verify your work and provide content assist against a specification. If you are editing a plain XML file that provides no DTD or schema, the editor still provides syntax highlighting and basic, best-guess content assist for you as well as basic validation (like unclosed tags). However, some of the more advanced features for your editing won’t be available without a DTD or schema.


3. Preferences

The XML editor preferences can control everything from how the syntax highlighting looks (e.g. color of tags and attributes), to how the page formats when the formatter is run.

Access these preferences by selecting Window>Preferences from the menu, expanding MyEclipse>Files and Editors>XML, and selecting XML Files.


XML editor preferences

Another feature of the XML editor that many developers might want to use is template support. Templates are a way to assign a short keyword to a body of text that can be inserted directly into a file that is being edited along with some basic variable replacement (like timestamps, usernames, etc.). Templates can be accessed from the XML Files>XML Source>Templates sub-preference.


XML templates preferences