Posts Tagged ‘XML’

Fall 2009 Courses

Sunday, August 23rd, 2009

This coming Fall term I will be teaching two courses at Concordia University’s Centre for Continuing Education. They are Java Programming Fundamentals on Tuesdays and Web Services and XML Processing on Mondays. The times for both classes are from 6 PM till 10 PM.

Java Programming Fundamentals (CEJV419/A1 from 2009-09-15 till 2009-11-17)

 The objective of this course is to introduce object oriented programming using the Java language to students who have already been exposed to and used another programming language. What this means is that the course does not spend much time on how to write a loop or a selection statement. Rather, the way that Java implements these and other common language constructs will be reviewed.

The primary focus of this course is how to use Java to write truly object oriented programs. The concepts of developing classes that cooperate and work with other classes and implementing them as objects will be covered. The libraries unique to Java such as Swing and JDBC will be explored but creating classes to solve problems will be paramount to the course.

Web Services and XML Processing (CEJV659/A1 from 2009-09-14 till 2009-11-23)

As the name implies there are two major topics in this course. The first is creating, writing, and reading files in the XML format. XML is the standard by which designers and programmers communicate information between processes on single computers and networks of computers. XML is a meta‑language or language for creating languages that provides a framework for developing specific formats of communication. Java has a very sophisticated family of libraries for XML and the course will examine them and see how they are used.

We typically write software that at some level contains methods or functions that we call upon to perform some work on our behalf. These are typically contained within the executable code of our programs. A Web Service turns this arrangement sideways by placing the methods on other computers somewhere on a network or the Internet itself. By using protocols that work within the protocols associated with Web Servers (hence the name Web Service) programs can be written without regard to the physical location of the code. Java provides the necessary framework and code to make using these services as easy as calling a local function. The format of the information that flows between an application on one computer and the web service it is consuming on another computer is a langauge created using XML.

For more information on these courses and other great courses at the Concordia University School of Extended Learning visit their web site at http://sarno.concordia.ca/conted/.

Null Pointer Error in XSLT Transformation

Monday, March 16th, 2009

In a recent lab session with my students one of them presented me with what I thought would be a simple problem to resolve. Their code was transforming a DOM into an XML document using the XSLT engine in Java 1.6. The source of the data was an ArrayList of JavaBeans created from a JDBC RecordSet. Creating the DOM went smoothly but when the transformation was called on a null pointer exception occurred. The stack trace pointed to a line of code that read:

transformer.transform(xmlSource, result);

So as I usually do I had the student add some System.out.println statements to determine which reference was null. To my surprise every reference was not null.

Next I had the student print out the values from the ArrayList’s JavaBeans as they were being entered into the DOM. We saw two things. First, one of the five special characters that must be an entity in an XML document was coming out of the beans. Second was the fact that some of the strings were null.

So I made a wrong assumption and then failed to test my assumption. I assumed that the problem was the special characters and so directed the students to create a method to replace the characters with their entities (i.e. & becomes &). The next day a student came to see me and suggested that the problem was really the null strings. So I finally got around to doing the tests.

What I learned is that the transformation of a special character in the DOM to an XML was being done as part of the transformation. There was no need to write a method to convert the special characters to entities on the way into the DOM. Doing what I said resulted in the characters that made up an entity remaining. For example:

Original string: cats & dogs

Converted string: cats & dogs

The converted string went into the DOM and then appeared in the XML as:

<housepets>cats &amp;amp; dogs</housepets>

Certainly not what is wanted so converting characters before they go into the DOM was not the solution and therefore special characters were not the problem.

The real problem is the null strings. While the DOM was happy to reference a null string, the transformation engine sees the string for what it really is, a null pointer.

The solution is to either check for null strings when building the DOM or to have the set methods in the beans recognize a null string and create an empty string in its place.

Problem solved and another successful demonstration that the teacher is human.