Accueil > WTP - XML Search > Eclipse WTP – XML Search [step1]

Eclipse WTP – XML Search [step1]

Many Java frameworks use XML files configuration to describe the framework behaviour. Spring, Jetty, Tomcat, Struts2, Hibernate… are Java frameworks which are configured with XML files. Take a sample XML file with Spring :


  <bean id="accountDaoBeanId"
      class="org.springframework.samples.jpetstore.dao.ibatis.SqlMapAccountDao" />

  <bean id="petStore"
    <property name="accountDao" ref="accountDaoBeanId"/>


In this sample you can notice you have several references :

  • XML Node 2 Java class : bean/@class reference a Java class.
  • XML Node 2 Java method : bean/property/@name reference the setter SqlMapAccountDao#setAccountDao
  • XML Node 2 XML node : bean/property/@ref reference the bean accountDaoBeanId.
  • It exists another references like XML node 2 file for instance.

Having a framework which is configured with XML files is cool, but I think it’s very important to have a good IDE which manage thoses XML files. Spring Tools Suite is a great Spring IDE for Eclipse which manage XML Spring files. You can benefit with completion, hyperlink, validation to manage XML references described below. Here a screenshot with completion for ref bean (XML Node 2 XML node) with Spring Tools Suite :

Develop a Spring Tools Suite-like to manage another XML files (Jetty, Struts2, custom XML descriptor..) for Eclipse is very hard. I have decided to create Eclipse WTP – XML Search that I would like to contribute to official WTP project (see bug 330576) which give you 2 features:

  • Search/XML… which add new Search UI dialog (like Search/File…, Search/Java…) to search from your workspace, XML nodes and files with XPath as pattern search.
  • Use XML search in your plugins which give you the capability to manage completion, hyperlink, validation (and Ctrl+Shift+G) to manage any XML files (Jetty, Struts2…). The basic idea is to declare with the Extenion Point « » the XML references (XML node 2 XML node, XML node to Java…) for your XML files and you benefit for completion, hyperlink, validation (and Ctrl+Shift+G). The goal of this extension point is to hide the completion, hyperlink, validation complexity development. To give you an idea, I have managed XML Jetty files and Struts2 XML files. For each project I have developped that into 4 hours.

I have decided to write several articles called « Eclipse WTP – XML Search [step*] » where I will present you the 2 features of the Eclipse WTP – XML Search. If you wish see screenshot and test XML Jetty and Struts2 plugins based on Eclipse WTP – XML Search, please read ODT files from TK-UI SVN/docs.

Search/XML…- UI dialog

WTP XML Search give you the capability to search XML nodes in your any XML files from your workspace with XPath like Search/File…(which is used to search some text in your files). In this article, I use XML Jetty files, but you can use WTP XML Search with any XML files.. XML Search engine is available with Search/XML… menu :

Manual XPath Search

Imagine you wish find every Nodes « Configure » from XML Jetty files, which declare «org.eclipse.jetty.server.Server» class. The XPath to use is :

/Configure[@class= »org.eclipse.jetty.server.Server »]/@class, you can fill this XPath in the XPath field :

After clicking on Search button, the Search view display the result of the search :

You can double-click on a node result to open the files. The XML editor opens the file and select the Node :

Lazy XPath Search

Fill the XPath in the XPath field can be boring. To do the same search that below, you can select a Node. In this sample we wish search the following nodes :

/Configure/Call[@name= »addConnector »]/@name

To do that open an XML file which follow this XPath and select the attribute name in the XML editor :

Open the XML Search (Search/XML…), the UI dialog opens and XPath field is automaticly filled:

XPath processor

XPath processor with UI Dialog

You can notice that there is a combo called XPath processor. This is used to choose your XPath processor implementation (XPath 1, 2.0 with Saxon, WST….). This combo is filled by default with Standard XPath evaluator (XpathFactory.newInstance()) which use XpathFactory.newInstance();

If you have Helios, you will have WST XPath 2.0 processor which use JflexCupParser.

XPath processor with Plugins wich use XML search (like Jetty plugin)

Completion, hyperlink, validation in XML editor use XPath. It’s possible to select the XPath procesor for that. You can go at Preferences XML->XML Search/Xpath processor :

Use XML search in your plugins (ex : Jetty)

WTP XML Search give you the capability to manage completion, hyperlink, validation and Ctrl+Shift+G (to retrieve referenced nodes) in your plugins. I will describe in the next step2 the XML Jetty plugins to show you the features of the XML Jetty plugins and how develop your own plugins based on WTP XML search.

Just for you introduce what you can do it with WTP XML Search extension point, take a sample with XML Jetty files with XML nodes 2 XML nodes references. XML Jetty file use Ref element to reference an another XML node (Ref/@id =>*/@id). Take a real sample :

<New id="MBeanContainer" class="org.eclipse.jetty.jmx.MBeanContainer">
      <Ref id="MBeanServer" />

  <Get id="Container" name="container">
    <Call name="addEventListener">
        <Ref id="MBeanContainer" />

Here the Ref element with id=MBeanContainer is linked to New element with id=MBeanContainer. To declare this reference you do it with Extension Point like this (the real declaration is a little more complex to manage for instance Images used in the completion):

			<from path="/Configure//Ref"
				  targetNodes="@id" />
			<to path="/Configure//" 
					targetNodes="@id" />							

Once you have declared this reference you benefit with completion, validation, hyperlink and Ctrl+Shift+G (to retrive referenced nodes).

XML completion

If you open the completion (Ctrl+Space) on Ref/@id attribute, completion display the whole Configure,New…/@id that you have declared in your XML Jetty files :

XML hyperlink

You can use Ctrl+click to select the referenced Node. Select the Ref/@id attribute and do Ctrl, the attribute value appears as hyperlink :

If you click on the link it opens the XML file (if referenced node is declared in another file) and select the attribute :

XML validation

When New/@id doesn’t exist, a red error marker appears :

XML Ctrl+Shift+G to find references Nodes

You can use Ctrl+Shift+G to find references node. For instance if you select New/@id attribte and you do Ctrl+Shift+G the XML search is launched and display the Ref/@id linked to the New/@id.

Here a screen after doing Ctrl+Shift+G on New/@id=MBeanContainer. The search result display the New/@id linked :


I hope the features of WTP XML Search please you. I’m developing WTP XML Search for Jetty, Struts2 and custom XML descriptor. WTP XML Search start to manage several reference (XML node 2 Java, XML node 2 Java method, XML node 2 file, XML node 2 static value…).

In the next article [step2], I will explain how manage completion, text hover, hyperlink, validation for web.xml with WTP/XML Search.

Catégories :WTP - XML Search
  1. eldn
    décembre 21, 2010 à 3:54

    Thank you! This are really great news for me. your contribution is much appreciated.

  1. janvier 17, 2011 à 1:53

Votre commentaire

Entrez vos coordonnées ci-dessous ou cliquez sur une icône pour vous connecter:


Vous commentez à l’aide de votre compte Déconnexion /  Changer )

Photo Google

Vous commentez à l’aide de votre compte Google. Déconnexion /  Changer )

Image Twitter

Vous commentez à l’aide de votre compte Twitter. Déconnexion /  Changer )

Photo Facebook

Vous commentez à l’aide de votre compte Facebook. Déconnexion /  Changer )

Connexion à %s

%d blogueurs aiment cette page :