|
This post originated from an RSS feed registered with Java Buzz
by Levent Gurses.
|
Original Post: XML and Eclipse
Feed Title: Levent Gurses' Journal
Feed URL: http://jroller.com/rss/gursesl
Feed Description: Levent Gurses' Journal
|
Latest Java Buzz Posts
Latest Java Buzz Posts by Levent Gurses
Latest Posts From Levent Gurses' Journal
|
|
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).

Figure 1 XML File Associations in Eclipse
Checking Well-Formedness
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:
<action-mappings>
&action_mappings_xml;
</action-mappings>
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 ).

Figure 3 Eclipse proxy setup
Checking XML Validation
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
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd" >
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//EN as PUBLIC id, and http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd as SYSTEM id (See Figure 4 Defining a new DTD for struts-config).

Figure 4 Defining a new DTD for struts-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 in struts-config )

Figure 5 Failed validation in struts-config
System Information:
Windows 2000
JDK 1.4.2_03
Eclipse 3.0
XMLBuddy 2.0
About the author
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.
Read: XML and Eclipse