A client-side call

The main( ) method of the ResultSetElements class is executed in a client environment. It copies the file OrderResultSet.xml, constructs a ResultSetXml document from it, and then accesses and updates the columns of the ResultSet.

import java.io.*;
import util.*;
public class ResultSetElements {
    public static void main ( String[] args) {
       try{
		String xml =
 			FileUtil.file2String("OrderResultSet.xml");
 		xml.resultset.ResultSetXml rsx 
                 = new xml.resultset.ResultSetXml(xml);
		// Get the columns containing customer and date info
 		String cname = rsx.getColumn(0, "CustomerName");
 		String cid   = rsx.getColumn(0, "CustomerId");
 		String date = rsx.getColumn(0, "Date");
		// Get the elements for item 1 (numbering from 0)
 		String iName1 = rsx.getColumn(1, "ItemName");
 		String iId1 = rsx.getColumn(1, "ItemId");
 		String iQ1 = rsx.getColumn(1, "Quantity");
 		String iU = rsx.getColumn(1,  "unit");        
		System.out.println("\nBEFORE UPDATE: ");
 		System.out.println("\n   "+date+ "  "+ cname + " " +
 			cid);
 		System.out.println("\n   "+ iName1+" "+iId1+" "
 			+ iQ1 + " " + iU + "\n"); 
		//  Set the elements for item 1 (numbering from 0)  
 		rsx.setColumn(1, "ItemName", "Flange");
 		rsx.setColumn(1, "ItemId", "777");
 		rsx.setColumn(1, "Quantity","3");
 		rsx.setColumn(1,  "unit", "13"); 
		//  Get the updated elements for item 1 (numbering
 			from 0) iName1 = rsx.getColumn(1, "ItemName");
 		iId1 = rsx.getColumn(1, "ItemId");
 		iQ1 = rsx.getColumn(1, "Quantity");
 		iU = rsx.getColumn(1,  "unit");        
		System.out.println("\nAFTER UPDATE: ");
 		System.out.println("\n   "+date+ "  "+ cname + " " +
 			cid);
 		System.out.println("\n   "+ iName1+" "+iId1+" "
 			+ iQ1 + " " + iU + "\n"); 
 
          //  Copy the updated document to another file
 		FileUtil.string2File("Order-updated.xml",
 			rsx.getXmlText());
		} catch (Exception e) {
 		System.out.println("Exception:");
 		e.printStackTrace();
 		}
 	}
 }

The FileUtil.string2File( ) method stores the updated ResultSet in the file Order-updated.xml. The ResultSetMetaData of the updated document is unchanged. The updated ResultSetData of the document is as follows with new values in the second item.

<ResultSetData>
     <Row>
       <Column name="Date">1999-07-04 00:00:00.0</Column>
       <Column name="CustomerId">123</Column>
       <Column name="CustomerName">Acme Alpha</Column>
       <Column name="ItemId">987</Column>
       <Column name="ItemName">Widget</Column>
       <Column name="Quantity">5</Column>
       <Column name="unit">1</Column>
     </Row>
     <Row>
       <Column name="Date">1999-07-04 00:00:00.0</Column>
       <Column name="CustomerId">123</Column>
       <Column name="CustomerName">Acme Alpha</Column>
       <Column name="ItemId">777</Column>
       <Column name="ItemName">Flange</Column>
       <Column name="Quantity">3</Column>
       <Column name="unit">13</Column>
     </Row>
     <Row>
       <Column name="Date">1999-07-04 00:00:00.0</Column>
       <Column name="CustomerId">123</Column>
       <Column name="CustomerName">Acme Alpha</Column>
       <Column name="ItemId">579</Column>
       <Column name="ItemName">Type 3 clasp</Column>
       <Column name="Quantity">1</Column>
       <Column name="unit">1</Column>
     </Row>
   </ResultSetData>
 </ResultSet>