Where Location is not the Key

When it comes to real estate, we all know the truth that location is the key.  Here I'm talking about xml schemaLocation, which is not necessarily the key in xml processing.  This is what W3C says:

... provides hints from the author to a processor regarding the location of schema documents...The presence of these hints does not require the processor to obtain or use the cited schema documents, and the processor is free to use other schemas obtained by any suitable means, or to use no schema at all.

In J2EE/JavaEE world, application servers are required to ignore any schemaLocation attributes in standard descriptors.  These descriptor files, e.g., web.xml, ejb-jar.xml, application-client.xml, application.xml, persistence.xml, etc, are portable across all application servers, and their schemas have been standardized.  Application servers know how to validate these descriptors.  The schemaLocation attribute in a web.xml/ejb-jar.xml would be redundant at best.  Practically speaking, no application server would fetch schemas at external web sites, such as http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd.

This is not to say schemaLocation is totally useless.  I find it helpful in certain circumstances:

Manual validation and reference: If I send a copy of my ejb-jar.xml to someone else, he/she can go to the schemaLocation as cited in ejb-jar.xml, and learn its structure and requirments.  Ideally, this should be done by appservers and tools, but let's say he/she doesn't have access to them at the moment.  Maybe I should tell him/her that the cited schema ejb-jar_3_0.xsd doesn't mean anything to application servers.

Even some tools and IDEs don't have a complete xml catalog of common JavaEE schemas.  So schemaLocation is their only hope to be able to validate these xml files.  But once the schemas at public web site get obsolete, these tools won't validate correctly.  This can happen when your project evolves ahead of the published schemas and your write xml files according to the newer schemas in your project.

technorati tags: , ,

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Cheng Fang

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today