- All Implemented Interfaces:
- org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler
public class CSVSAXHandler
extends org.xml.sax.helpers.DefaultHandler
This file was written with the goal of parsing large blocks
of XML consisting of records from the conversation service, and
converting them into a CSV format.
Use this ContentHandler with an XML reader when the using
the default ContentHandler is impractical because of the size
of the XML object being read.
Example:
ContentHandler saxWriter = new CSVSAXHandler(outputStream, gridColumnNames);
XMLReader xr = XMLReaderFactory.createXMLReader();
xr.setContentHandler(saxWriter);
High-level processing flow of this class:
1) At the start of every XML element, call startElement().
a) if the XML element is a , set writingRecord flag to true
b) if writingRecord is already true, it means we are parsing an attribute inside a record
i) if the current attribute has a display value, insert/append that value to the attribute in the column
map and set the useElementContents to false
2) For the text content between start/end of every XML element, call characters()
a) if the writingRecord and useElementContents flags are both true, insert/append the text content to the
attribute in the column map
b) If this is the second time characters has been called in a row without another call to startElement, this is
treated as a continuation of the string by the parser, and not a multi-assign. As such, it is not delimited.
3) At the end of every XML element, call endElement().
a) if the XML element is a , then:
i) set writingRecord flag to false
ii) write everything in the column map to the browser as CSV
iii) clear the column map