return to index
xsdb project page with download links
xFeedMe xsdb resources

xsdbXML java implementation notes

The java xsdbXML implementation allows programs to use the xsdbXML framework in java enabled applications and also provides a number of useful related java applications.

Running programs with the java implementation of the xsdbXML framework requires the installation of the java 2.0 J2EE 1.4 runtime environment or equivalent. Compiling and building the framework requires the installation of the J2EE development environment or better.

The java modules consist of the NET.sourceforge.xsdb.xsdbXMLj package and some applications which use the package. All of the components are rooted at the INSTALL_DIRECTORY/xsdbXML/xsdbXMLj directory.

Building any of the applications using the java compiler will trigger compilation of the NET.sourceforge.xsdb.xsdbXMLj package. For example the following command line sequence builds the localtest application and then runs the application.

INSTALL_DIRECTORY\xsdbXML\xsdbXMLj> java localtests
At present all of the java example applications are "command line" applications which normally run within a console window.

To run the applications conveniently from any current directory make sure that the root directory INSTALL_DIRECTORY/xsdbXML/xsdbXMLj is on your java "class path". For example on my Windows/NT based machine I set the following environment variable in my MSDOS window

...> SET CLASSPATH=C:\xsdbSourceForge\xsdbXML\xsdbXMLj
and afterwards I may run "java RunTests" (for example) from any current directory within that window.

java applications

There are several applications associated with the framework.

The java application programmers interface

The primary interface to the framework from an external program is mediated by instances of the NET.sourceforge.xsdb.xsdbXMLj.Query class.

Create a Query for a literal query text using the constructor

public Query(string text, string contextLocation, bool verbose)
Where text is the body of the query, contextLocation is a directory path used to resolve relative file system references and verbose boolean flag which when set true causes the framework to generate debugging output. The alternate constructors
public Query( stream, String contextLocation, int length, boolean verbose)  
public Query(String filename, boolean verbose) 
are similar, but these constructors get the query text from a stream or a file content respectively. The last constructor infers the contextLocation from the filename path.

A program may extract the result of a query as an XML string, an ArrayList of ArrayLists or as an ArrayList of Hashtables as explained below.

The result of a normal xsdb evaluation is a sequence of mappings from names to values. The Query.Dictionaries(...) method presents the result as a sequence of Hashtables where the keys for the table are the names and the values for the table are the values associated with each name. The Query.Tuples(...) method presents the result as a sequence of ArrayLists containing the values associated with the names. If the order of the names is specified in the query the values are provided in the order requested, otherwise the values are provided sorted alphabetically by the associated name. The Query.StringResult(...) method presents the result as an xml string similar to those generated by the query and test applications.

The signatures of these methods are

public ArrayList Dictionaries(bool strict) 
public ArrayList Tuples(bool strict)
public string StringResult(bool strict) 
In each case the strict parameter will trigger an exception if the result of the query cannot be converted to a purely positive form.

The included APIDemo application provides a very simple demonstration of each of these methods. The main method for the application is listed below
	public static void main(String[] args)
		// Initialize a query from a String literal
		String querytext = (
			"<query names=\"salutation age\" sort=\"age\">\n"+
			"	<and>\n"+
			"		<s at=\"salutation\">hello kind world</s> <i at=\"age\">0</i>\n"+
			"	</and>\n"+
			"	<and>\n"+
			"		<s at=\"salutation\">goodbye cruel world</s> <i at=\"age\">99</i>\n"+
			"	</and>\n"+
		System.out.println("query text = \n"+querytext);
		Query Q = new Query(querytext, "\\" ,false);
		System.out.println("\n\n String result is\n"+Q.StringResult(false));
		System.out.println("\n\n hash table result");
		ArrayList Hashes = Q.Dictionaries(false);
		//foreach (Object thing in Hashes) 
		for (int i=0; i<Hashes.size(); i++) 
			Hashtable H = (Hashtable) Hashes.get(i);
			int age = ((Integer)H.get("age")).intValue();
			String salutation = (String)H.get("salutation");
			System.out.println("age="+age+"  salutation="+salutation);
		System.out.println("\n\n array list result");
		ArrayList tuples = Q.Tuples(false);
		//foreach (Object thing in tuples) 
		for (int i=0; i<tuples.size(); i++) 
			ArrayList A = (ArrayList) tuples.get(i);
			int age = ((Integer)A.get(1)).intValue();
			String salutation = (String)A.get(0);
			System.out.println("age="+age+"  salutation="+salutation);
This console application generates the following standard output
query text =

<query names="salutation age" sort="age">
                <s at="salutation">hello kind world</s> <i at="age">0</i>
                <s at="salutation">goodbye cruel world</s> <i at="age">99</i>

 string result is
    <s at="salutation">hello kind world</s>
    <i at="age">0</i>
    <s at="salutation">goodbye cruel world</s>
    <i at="age">99</i>

 hash table result
age=0  salutation=hello kind world
age=99  salutation=goodbye cruel world

 array list result
age=0  salutation=hello kind world
age=99  salutation=goodbye cruel world

Arithmetic expressions

The arithmetic expressions used in the calc and cond predicates match the Python implementation except that certain arithmetic functions supported in Python are not yet supported in the java implementation. In particular the java implementation supports the following arithmetic functions within arithmetic expressions.
Signature Summary
int(x), float(x), str(x) Data type conversion.
round(x), floor(x), ceil(x)
abs(x), sqrt(x), log(x)
sin(x), cos(x), tan(x)
asin(x), acos(x), atan(x)
sinh(x), cosh(x), tanh(x)
Standard floating point functions.
e(), pi() Function notation for floating point constants.
strip(s), upper(s), lower(s)
find(inString, pattern [, start [,end]])
string functions.
max(x.y), min(x.y)
count(x.y), avg(x.y), med(x.y)
Group aggregate operations.
These functions have the same semantics as in the Python implementation.
End of xsdbXML java implementation notes
return to index