One of the things I like about Eclipse is the abundance of
high-quality plugins. These are generally fairly simple to install and
use and most importantly they are free. XML is no exception and one
such great plugin is XMLBuddy
2.0 (http://xmlbuddy.com/2.0/download.php).
XMLBuddy 2.0
XMLBuddy is a free multi-talented plugin for Eclipse which among other things can
be utilized for two important XML tasks: checking for well-formedness and
validation. You can download the Eclipse 3.0 version of the plugin
from http://xmlbuddy.com/2.0/d.php and extract the contents to your ECLIPSE_HOME/plugins
folder. After the extraction you will see a new menu "XML" added to your
perspective.
To tell Eclipse to use XMLBuddy as your default editor for XML files
you need to associate those files with XMLBuddy. Launch Eclipse and
open
Window/Preferences/Workbench/File Associations. Find *.xml and select XMLBuddy(Default) (See Figure 1 XML File Associations in Eclipse).
In your Resources perspective, double-click any XML file, for instance struts-config.xml. Initially, this document appears to be well formed. To test the plugin, erase any tag in the document:
Save. Notice the red X inside the text editor and the associated problem in the Problems view.
Figure 2 Red X appears right after the deletion of<action-mappings>
This is a good sign; it shows that XMLBuddy has actually plugged-in to Eclipse.
Eclipse Setup
Before starting XML validation, it's a good idea to verify your
connection settings. If you share a proxy server, you will have to let
Eclipse know about it in order to fetch DTD files from the Internet.
Navigate to Window | Preferences | Install/Update. In Proxy settings, check Enable HTTP proxy connection and enter your HTTP proxy host address and your HTTP proxy host port (See Figure 3 Eclipse proxy setup ).
Now, put the <action-mappings>
tag back and make sure the red X disappears. This time, you are going
to validate the XML against the schema or DTD as defined in its
DOCTYPE. The header of the file reads
You need to tell Eclipse to load this DTD and validate your document against it. For this, navigate to Window/Preferences/XMLBuddy/XML/Validation/DTD. Click on New? Enter struts-config as Root name, "-//Apache Software Foundation//DTD Struts Configuration 1.1//ENas PUBLIC id, and http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd as SYSTEM id (See Figure 4 Defining a new DTD forstruts-config).
Also, while you are still in the XMLBuddy preferences, check Validate on save. Now, you can close Preferences. Click on your file in the text editor. Go to XML | Validate. If nothing happens, your file is valid. To verify, go to any place in the XML document and add a bogus tag. Save or click XML | Validate. Validation should fail (See Figure 5 Failed validation instruts-config )
Levent
Gurses is a Washington, DC-based technology consultant. He is also one
of the co-founders of Jacoozi,
an integrated solutions provider based in Alexandria, VA. In his
professional life Levent helps clients overcome their J2EE challenges
and develop leaner and meaner software development practices. Most of
his free time goes in reading and motorcycle racing.