272 The XML Files: Develo pment of XML/XSL Applications Using WebS phere Studio
queryProperties.setFormat("GENERATE_AS_ELEMENTS");
queryProperties.setRecurse(false);
}
Executing the SQLToXML class
We created the doQuery method to execute the query and get an XML
Document as a result (Example 11-8). SQLToXML returns XML data as a stream,
and it only accepts an instance of PrintWriter. To get it as a string data, you need
to create an instance of StringWr iter, then create an instance of PrintWriter from
the StringWriter.
Example 11-8 CustomerXSLServlet doQuery method
//For Application Developer 4.0.3
private StringWriter doQuery(HttpServletRequest request){
StringWriter xmldata = new StringWriter();
PrintWriter xmlwr = new PrintWriter(xmldata);
try{
sql2xml.execute(new java.lang.String(
request.getParameter("memberhsip")),xmlwr,null,null,null);
}catch(Exception exception){
System.out.println(exception);
}
return xmlData;
}
//For Application Developer 5.0
private org.w3c.dom.Document doQuery(HttpServletRequest request){
StringWriter xmldata = new StringWriter();
PrintWriter xmlwr = new PrintWriter(xmldata);
try{
sql2xml.setParameters(new java.lang.String(
request.getParameter("memberhsip")));
sql2xml.execute();
}catch(Exception exception){
System.out.println(exception);
}
return sql2xml.getDocument();
}
Tip: A future release of Application Developer contains a method to get a
document. We tested this method and it works. When it is available, you can
get a document directory from SQLToXML.