Photo
Overview
The XJ programming language is designed as a strict extension of Java 1.4. Java 1.4 programs can be compiled by the XJ compiler ( xjc ), which will generate class files like any other javac compiler. XJ adds three main constructs to Java 1.4:
  • Import of XML Schemas: An XML Schema is treated by XJ similar to an import of a package in Java. For example, import salesschema.*; imports all global element declarations in the schema. The global elements in the schema can now be used as class references anywhere in the compilation unit. Local element declarations nested in global declarations are named similarly to nested classes in Java.
  • XPath Expressions: A programmer may write XPath expressions inline in the XJ program. The compiler ensures that the XPath expression is valid with respect to the XML Schemas imported by a program.
  • XML Construction: A programmer may construct XML data in an XJ program by writing literal XML inline in the Java program. The compiler will verify that the construction is valid with respect to the appropriate Java type.
The XJ programming language adds a set of classes to the standard class library defined by Java (See Figure 1). At the root of this set of classes is the XMLObject class, which corresponds loosely to the Node class in DOM. The XMLObject class and its subclasses are treated specially by the XJ compiler:
  • XPath expressions can be evaluated only on instances of these classes.
  • Instances of these classes may be constructed from literal XML.
  • XJ extends the Java type system to allow programmers to declare variables, methods, and fields using types imported from XML Schema declarations. Element and atomic type in XML Schema declarations are translated to subclasses of XMLObject.

Figure 1: The hierarchy of XJ types
\begin{figure}\centering\setlength{\unitlength}{1pt}%%
\begin{picture}(304,145)(...
...tvector(0,-1){18}}
\par\put(240,49){\vector(0,-1){18}}
\end{picture}\end{figure}

In the class hierarchy, XMLElement is the superclass of all classes corresponding to XML element declarations, and XMLAtomic is the superclass of all classes corresponding to XML atomic types. The XMLObject and XMLAtomic classes are abstract and instances of them cannot be constructed directly. Instances of XMLElement may be constructed.

The result of an XPath expression is always an instance of a Sequence class, which corresponds to an ordered list of zero-or-more XMLObject. The XMLCursor class implements the java.util.Iterator interface, and is used to iterate over instances of the Sequence class. Both of these classes support a limited form of genericity as defined in Java 5.0 to support more robust typechecking. The classes in the com.ibm.xj.io package support serialization of XML data to java.io.OutputStream.


 

    About IBM Privacy Contact