Abbey Workshop | ||||||||||
This tip demonstrates a mapping technique for extracting data from an XML file. This basic technique can be used in a number of different situations. The key is the code in the handler class.
Line 58 defines a CharArrayWriter class that that is used as a buffer for this class. On line 65, the buffer is reset when an element start tag is encountered in the startElement() method. This removes any characters that may have been encountered before an element we are interested in. When the endElement() method is called on lines 73 - 83, a check is made to see if it is one of the elements we are interested in. If it is a name or phone element, then the data in the buffer is processed. In this simple example, it is simply printed out.
Download source for: SaxMap.java
Copyright © Abbey Workshop 2006