SAXBuilder builder = SAXBuilderHelper.createSAXBuilder(false);
Document resultsDocument = builder.build(resultsFile);
List resultElements = resultsDocument.getRootElement().getChildren(TagNames.Elements.QUERY_RESULTS);
Iterator iter = resultElements.iterator();
while ( iter.hasNext() ) {
Element resultElement = (Element) iter.next();
if ( resultElement.getChild(TagNames.Elements.SELECT) == null ) {
// We've got an exception
Element exceptionElement = resultElement.getChild(TagNames.Elements.EXCEPTION);
if ( exceptionElement != null ) {
// ---------------------------------
// Add the ExceptionType element ...
// ---------------------------------
Element typeElement = new Element(TagNames.Elements.EXCEPTION_TYPE);
typeElement.setText(exceptionElement.getChild(TagNames.Elements.EXCEPTION_TYPE).getTextTrim());
parent.addContent(typeElement);
// ---------------------------
// Add the Message element ...
// ---------------------------
Element messageElement = new Element(TagNames.Elements.MESSAGE);
String msg = exceptionElement.getChild(TagNames.Elements.MESSAGE).getTextTrim();
messageElement.setText(StringUtil.removeChars(msg, new char[] {'\r'}));
parent.addContent(messageElement);
// -------------------------
// Add the Class element ...
// -------------------------
Element classElement = new Element(TagNames.Elements.CLASS);
classElement.setText(exceptionElement.getChild(TagNames.Elements.CLASS).getTextTrim());
parent.addContent(classElement);
}
} else {
// We've got results
// -------------------------------
// Read the SELECT elements
// -------------------------------
Element selectElement = resultElement.getChild(TagNames.Elements.SELECT);
resultElement.removeChild(TagNames.Elements.SELECT);
parent.addContent(selectElement);
// -------------------------------
// Read the TABLE of data
// -------------------------------
Element tableElement = resultElement.getChild(TagNames.Elements.TABLE);
resultElement.removeChild(TagNames.Elements.TABLE);
parent.addContent(tableElement);
}
}
return parent;