Deployment Descriptor (XML) Editor

This editor includes advanced XML editing functions.  Here you will learn about:

  • Editor functions
  • Web XML editing

This feature is available in MyEclipse.

1. Web XML Editor

The MyEclipse Web XML editor includes advanced XML editing functions like:

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

When you create a Web project, the New Web Project wizard places a default web.xml file in the project’s WEB-INF folder. To open the web.xml file, double-click it in the Project Explorer view. The Web Deployment Descriptor editor opens. Even though the Web Deployment Descriptor editor provides a Source view of the web.xml file (by clicking the Source tab), using the Design view is easier and introduces fewer errors. As you make changes on these pages, the web.xml file is updated automatically for you.


Web Deployment Descriptor editor for XML files

The tree structure is also shown in the Outline view and the Project Explorer view and provides easy navigation to the individual sections of the web.xml file.


Outline view

2. Web XML Editing

To edit the deployment descriptor, click the nodes in the tree to locate attributes you want to add, edit, or remove. The Web deployment descriptor editor lets you specify deployment information for modules created in the Web development environment. The information appears in the WebContent/WEB-INF/web.xml file. Note that you use the Web deployment descriptor to set deployment descriptor attributes. You do not use it to manipulate Web resource content directly.

Editing web.xml files using the MyEclipse Web 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.


Switch modes with the tabs


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

2.1 Web XML Design Mode

When you first open a web.xml document in the Design mode, it looks like the following image.


Design view

In the Design mode, the contents of the web.xml document are shown to you in something of a “super” outline view. On the left side you have the tags that make up your document represented in the form of a tree, each of which you can edit. Clicking on any tag in the tree displays the attributes for that tag in edit mode on the right side, making it very easy to visually understand and edit an web.xml file without worrying about syntax problems.

Another nice feature of the Design mode is that you can add, remove, and edit tags visually, and the Designer provides you with only 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 or attribute.

As an example, let’s say you want to add a context-param argument in the XML document. A context-param is a simple name/value pair with an optional description. Select the Context Parameters node in the tree, and click the Add icon.


Adding a context parameter

According to the Schema referenced by the document, you can have zero or more context-params in any given web.xml file. They consist of a name, value and an optional description. The Param-Name and Param-Value is determined by what frameworks you’re using and what those frameworks expect to see as parameters. This example uses JSF and is specifying where the config file resides at runtime. Other frameworks use other parameters.


Adding context param values

After you add a tag, you can edit values or add/remove tags without switching to the Source mode for editing. Double-click the field you want to edit.


Editing a context param

2.2 Web XML Source Mode

While editing XML documents in design mode can be easier at times and save you from making errors, it can also be handy to work directly with the source code. MyEclipse’s XML Editor provides extensive source-editing features.

When you first open an XML document in Source mode, it looks like this:


Source view

Note: The red underlines in the screenshot above are from the universal editor spell checker. You can enable or disable the spell checker for all editors based on your preference.

When using the XML source editor you might notice some very nice tooling as you work. For example, if you mistype a tag or attribute name the editor marks the line as an error (checked against the DTD or Schema referenced by the doc).


XML errors are marked for you

To make editing easier, content assist is available for tags and attributes. The content assist is also context-aware, so it does not suggest illegal completion options to you based on the position of your cursor and the DTD or Schema the XML file is referencing.


Content assist helps you complete code

Many of the functions provided by the MyEclipse Web XML editor depends on the document’s reference to 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 content assist for you as well as basic validation (like unclosed tags). However, some of the more advanced editing features are unavailable.

3. Resources & Related Topics