Java Reference
In-Depth Information
try{
Element root = xmlDoc.getDocumentElement();
Element row = (Element)xmlDoc.createElement(sql.tableName);
root.appendChild(row);
for(int i=0;i<data.size();i++){
String cName = (String)columnNameVector.elementAt(i);
String cType = (String)columnTypeVector.elementAt(i);
String cData = (String)data.elementAt(i);
if(cData.startsWith("'")&&cData.endsWith("'")){
if(cData.length()>1){
cData=cData.substring(1,cData.length()-1);
}
}
if(cType.equals("ATTRIBUTE")){
row.setAttribute(cName,cData);
}else{
Element column = xmlDoc.createElement(cName);
row.appendChild(column);
column.appendChild(xmlDoc.createTextNode(cData));
}
}
}catch(Exception e){
System.err.println("Insert error: "+e);
}
return true;
}
public Document getXmlDocument(){
return xmlDoc;
}
}
The XMLQuery object returns an XMLResultSet , which implements java.sql.ResultSet . The
ResultSet is a container for the data the query returns. Since this application deals with XML, the
ResultSet is maintained as a DOM document containing the specific elements and child elements
requested.
The XMLResultSet
The most important methods of XMLResultSet are next() and getString() . The next() method
uses the NodeList rows to iterate through the nodes making up the ResultSet . When next() is first
called, it initializes the NodeList from the ResultSet document. It then maintains a cursor pointing to
the current row in the int rowIndex .
The getString() method shown in Listing 19-6 is implemented using only the column-name variant.
There are two reasons for this:
Search WWH ::




Custom Search