Java Reference
In-Depth Information
 
Since XMLResultSet is intended to support data stored either as attributes or as elements;
position is meaningless.
 
XML processors frequently reorder child nodes; once again, position is rendered meaningless.
Notice how getString() first looks for an attribute node and then looks for a matching element. It is
usually quicker to retrieve an attribute.
Listing 19-6: The XMLResultSet class
package JavaDatabaseBible.ch19.JDBCforXML;
import java.io.*;
import java.sql.*;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.apache.xerces.dom.DocumentImpl;
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.XMLSerializer;
import JavaDatabaseBible.ch19.JDBCImpl.JDBCResultSetImpl;
/**
* XMLResultSet is based on a document which is built by
* XMLStatement.executeQuery().
* This class provides the tools to traverse the document
* and return nodes by row & column.
*/
public class XMLResultSet extends JDBCResultSetImpl {
private int rowIndex = -1;
private int rowCount = 0;
public Document xmlDoc;
private Element root = null;
private Element currentRow = null;
private NodeList rows = null;
public XMLResultSet() throws SQLException {
xmlDoc = new DocumentImpl();
root = (Element)xmlDoc.createElement("RESULTSET");
xmlDoc.appendChild (root);
}
private void initialise(){
if(rows==null){
root = xmlDoc.getDocumentElement();
Search WWH ::




Custom Search