|
|
1.
Preface
This document was written using
MyEclipse and all screenshots are based upon the default
user interface settings for MyEclipse
and Windows XP. If you experience difficulty with the
instruction of this document, please see the
User Feedback section for how to
provide feedback to the MyEclipse documentation team.
|
|
2.
Introduction
This document will cover some
of the functionalities available in the MyEclipse XML Editor.
The MyEclipse XML editor includes advanced XML editing
functionalities like:
-
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
|
3.
XML Editing
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:
|
Figure 1. Switch-mode tabs
|
Switching between the two modes can be done any time as they are
both kept in sync with each other automatically. First we will
take a look at the
Design Mode.
|
3.1
XML Design Mode
When you first open an XML document and switch to the
Design Mode, it will look something like this:
|
Figure 2. XML Design Mode view
|
In this mode the contents of your XML document are shown to you
in something of a glorified outline-view. Along the left column
you have the tags that make up your document and in the second
column you have the values for those tags. You can double-click
on 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 problems.
Another nice feature of using the
Design Mode is that you can add, remove and edit
tags visually and the designer will make sure to only provide you
with 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 somewhere.
As an example, let's say we wanted to add a
description to the first
context-param argument in our XML document:
|
Figure 3. Adding a description to
our context-param
|
You will notice at this point in the document, according to the
Schema referenced by our document, the only valid tags that can
be inserted here is a child
description tag, a comment tag or a generic processing
instruction tag. If we click on the
description tag, it is added and we can quickly edit the
description to something we want:
|
Figure 4. Adding our custom
description.
|
Editing any of the tag values or adding/removing child tags can
be done in this fashion without ever needing to switch to the
Source Mode for editing. Although editing the
source directly can be faster sometimes and some developers
prefer it, so let's take a look at that next.
|
3.2
XML Source Mode
While editing XML documents in design mode can certainly be
easier at times and save you from making errors, it's also
necessary (or preferred) to work directly with the source code.
If that is the case MyEclipse's XML Editor provides extensive
source-editing features that we will take a look at below.
When you first open your XML document to edit it, it will look
something like this:
|
Figure 5. XML source editor view
|
You'll notice a collection of views available to help you edit
your document. The source view on the left will look familiar to
many, then you have a simplified
Outline view on the top right, and
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 may not look identical to the
screenshot above).
All these views will stay in sync with the file you are editing
as you work. As you click inside of tags the
Properties view will show you the values for that tag,
if you decide to remove or add nodes using the
Outline view as shown here:
|
Figure 6. Using the Outline view
|
The
Outline view actually provides very similar
visual-editing functionality that the
Design Mode does if you'd prefer to use it.
If you decide to edit the XML source from the editor you will
notice some very nice assistance as you work. For example,
mistyping a tag or attribute name will get marked immediately for
you as an error (checked against the DTD or Schema referenced by
the doc):
|
Figure 7. XML errors are marked
for you
|
And to help make editing easier, content-assist is available for
tags and attributes. The content-assist is also context-away, so
it will not suggest illegal completion options to you based on
the position of your cursor:
|
Figure 8. Content-assist is
everywhere
|
Alot of the functionality provided by the MyEclipse XML Editor is
dependent on your document correctly referencing a DTD or Schema
such that 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 will
still provide syntax highlighting and basic best-guess
content-assist for you as well as basic validation (like unclosed
tags) but some of the more advanced features for your editing
won't be available.
|
4.
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.
All of these preferences can be accessed from
Window > Preferences > MyEclipse > Files and
Editors > XML:
|
Figure 16. XML editor preferences
|
Another feature of the XML editor that many developers may be
interested in making use of is the 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.). That functionality can be accessed from the
XML Templates sub-preference here:
|
Figure 17. XML templates
preferences
|
|
5.
Resources
This section provides some links to resources used during this
guide.
-
web.xml - Example XML file used
for the XML editing portion of this document.
|
6.
User Feedback
If you have comments or suggestions regarding
this document please submit them to the
MyEclipse
Documentation Forum.
|