One of the sessions I went to today was more of a discussion about the future of XML in Java. There was a proposal for a java.lang.XML class, and various tactics for including XML syntax in the language. You may have seen some of these they tend to look something like:


 XML xml = { <foo><bar>someVar</bar></foo>};

We saw several variations on this, but they were all pretty much functionally the same, with minor syntactical variations.

Frankly, I would like to see something a little more… radical.

One of the problems you always have to deal with in the XML world, wether working with SOAP or REST or POXs (Plain Old XMLs! Hey look, I coined a TLA!) is that basically Java data types just don’t match to what you can specify in a schema. java.lang.Integer can’t be defined with a 1..5 value limit. java.lang.String can’t be constructed with a length limit.

I think what I would like to see is an expansion of the java.lang.* and java.util.* classes applicable to include more schema-precise definitions:


@XMLAttribute
public Integer{1..5} getMyInt();
public void setMyInt( Integer{1..5} value );

//..
public void setListOfMyInt( List<Integer{1..5}>{minOccurs=1} );
//..
@XMLExclude
public DataSource getMyDataSource();

This gives you an introspect able value to match to schema definitions. I will grant you that the List above isn’t really pretty, but it contains the relevant data. This provides a very clear way, however, to map back to a schema. Annotations used to delineate between attributes and child elements, and Object can get a ” Element toXML()” method and perhaps a: MyClass.newInstance( Element ) method.

I don’t want to deal with XML “in the language,” and the proposals above still don’t get past the kind of conversions you have to do between bean classes and XML all over the place. The reason JAX-WS, and JAX-B2, to some degree, are better than what we have had before is that you simply do everything using the same Java idioms we have come to know and love. While I think XML support in the language is critical, I also think it has to be a real improvement. I am not sure the proposals I have seen to now actually are.