XML Enhances Java

| 3 Comments | 3 TrackBacks

If you thought it's only Microsoft who's working on integrating XML into the core of programming languages, look at what IBM does for Java. This is a manstream trend now. XML Enhancements for Java are an emerging technology from IBM, which provides a set of language extensions that facilitate XML processing in Java.

What are XML Enhancements for JavaTM?

XML Enhancements for Java (XJ) are a set of extensions to Java 1.4 that integrate support for XML, XML Schema and XPath 1.0 into the language. The advantages of XJ over existing mechanisms for XML development are:

o Familiarity (for the XML Programmer) : XML processing in XJ is consistent with open XML standards.
o Robustness : XJ programs are strongly typed with respect to XML Schemas. The XJ compiler can detect errors in uses of XPath expressions and construction of XML data.
o Easier Maintenance: Since XJ programs are written in terms of XML and not low-level APIs such as DOM or SAX, they are easier to maintain and modify if XML Schemas change.
o Performance: Since the compiler is aware of the use of XML in a program, it can optimize the runtime representation, parsing, and XPath evaluation of XML.
In XJ, one can import XML schemas just as one does Java classes. All the element declarations in the XML schema are then available to programmers as if they were Java classes. Programmers can write inline XPath expressions on these classes, and the compiler checks them for correctness with respect to the XML schema. In addition, the compiler performs optimizations in order to improve the evaluation of XPath expressions. A programmer may construct new XML documents by writing XML directly inline. Again, the compiler ensures correctness with respect to the appropriate schema. By integrating XML and Java, XJ allows programmers to reuse existing Java libraries in the development of XML code and vice-versa.
Here are some samples of what XJ allows:
XPath integration:
int min = 70; 
Sequence<year> ys = sd[|/year[sum(.//sales) > $min]|];
Inline XML construction:
region r = new region(<region> 
    <sales unit='GBP'>75</sales> 
Dynamic one:
float conversion = 1.9; 
salesdata s = 
  new salesdata( 
        <sales unit='Dollars'>{grossSales * conversion}</sales> 
And many more. Find XJ documentation here.

Related Blog Posts

3 TrackBacks

TrackBack URL: http://www.tkachenko.com/cgi-bin/mt-tb.cgi/479

In one of their recent post-JavaOne articles, eweek interviewed James Gosling about the future of the Java language and ...

Read More

In one of my recent comments to Steve Loughran, I mentioned that Java 7 (aka Dolphin)

Read More

In a previous entry, I argued on the need for native XML support in the Java programming language. During the last couple of days, there have been some interes...

Read More


Apparently you cannot do that in XJ, becuase of a strong typing:

"To construct untyped XML, that is, XML that is not to be validated with respect to any XML Schema, one can use the XML literal constructor defined for XMLElement:

XMLElement a = new XMLElement(<theyear>1998</theyear>);

where the argument to the constructor is any well-formed block of XML data. The type of the XML value constructed is XMLElement. The variable a cannot be assigned to the variable y declared above even though they are constructed from the same literal XML. The variable a is an instance of XMLElement, and the variable y is an instance of theyear, and an XMLElement may not be assigned to a theyear. "

I was wondering, is there a new "xml" type as well, so that I could say this:

XmlType xml = <region>
<sales unit='GBP'>75</sales>

region r = new region(xml);

What language does this remind me of.... ???

Oh, I know... It's COmega watered down! ;)

Still, pretty cool stuff for sure!

Leave a comment