Mercurial > hg > Blog
annotate content/Eclipse/validating-xml-documents.md @ 0:4cd9b65e10e4
initial import of the pelican based blog
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Fri, 28 Jun 2013 08:48:58 +0200 |
parents | |
children | bb1f035109da |
rev | line source |
---|---|
0
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
1 Title: Validating XML documents against your own schemas with Eclipse |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
2 Date: 2007-06-07 |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
3 Tags: XML |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
4 Lang: en |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
5 |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
6 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 |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
7 |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
8 <div class="highlight"><pre> |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
9 The matching wildcard is strict, but no declaration can be found for element 'mule:model-seda'. |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
10 </pre></div> |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
11 |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
12 and that autocomplete in the XML editor didn't work either. |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
13 |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
14 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): |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
15 |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
16 ![Eclipse XML preferences](|filename|/images/EclipseXmlCatalog.gif) |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
17 |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
18 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: |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
19 |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
20 ![XML Schema entry](|filename|/images/EclipseCatalogEntry.gif) |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
21 |
4cd9b65e10e4
initial import of the pelican based blog
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
22 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. |