Validating XML documents against your own schemas with Eclipse

07.06.2007 by Dirk Olmes

This week I started to work on Mule 2.0 which will be based on Spring. We’re dropping our own custom config format in favor of Spring’s xml format. This requires me to design the schema for the transports I’m working on as well as convert the configuration of the unit tests to spring config files. I noticed that Eclipse kept complaining

The matching wildcard is strict, but no declaration can be found for element 'mule:model-seda'.

and that autocomplete in the XML editor didn’t work either.

With a bit of googling I found out that the key to success is the proper definition of namespaces and their URLs. In the normal case (as with the spring schema) the schema file is published on the net and can be downloaded by the XML parser. Publishing the schema you’re just developing each time you make a change is cumbersome so I figured there must be a better way. The solution is to declare your schema in Eclipse’s XML catalog. Go to Preferences -> Web and XML -> XML Catalog (assuming that you have WTP installed) and declare a user entry for the schema you’re currently developing. Your Eclipse XML Catalog should look similar to this (just with more entries):

Eclipse XML preferences

Unfortunately, the validation and autocompletion still does not work if you don’t use a little trick to make things work. XML files can be associated to their schema in two ways: either you point the schemaLocation to the full URL where the schema file can be downloaded or you specify a XML catalog key. When not being processed by Eclipse’s XML editor the document should still work. We don’t publish an XML catalog for mule but if you use a little trick you can still make the editor validate correctly. As XML catalog key specify the full URL to the schema like this:

XML Schema entry

The XML catalog validation seems to have preference over the download of schemas from the web. So Eclipse sees the “URL” as catalog key and validates against your schema on disk. When running as part of mule, the schema will be validated by spring’s xml parser which uses other means of getting the schema file.


Comments

There are no comments yet.

Leave a comment
Your name:
Comment: