登 录
//输出CRSet中的内容 print(cr); }
//创建DOM4J documet对象 public static Document createDC(){ Document d=DocumentHelper.createDocument(); Element books=d.addElement("books");
Element book1= books.addElement("book"); book1.addAttribute("id", "1"); Element name1=book1.addElement("name"); name1.addText("A"); Element number1=book1.addElement("number"); number1.addText("10");
Element book2= books.addElement("book"); book2.addAttribute("id", "2"); Element name2=book2.addElement("name"); name2.addText("B"); Element number2=book2.addElement("number"); number2.addText("20");
Element book3= books.addElement("book"); book3.addAttribute("id", "3"); Element name3=book3.addElement("name"); name3.addText("C"); Element number3=book3.addElement("number"); number3.addText("30");
Element book4= books.addElement("book"); book4.addAttribute("id", "4"); Element name4=book4.addElement("name"); name4.addText("D"); Element number4=book4.addElement("number"); number4.addText("40");
d.setXMLEncoding("utf-8"); return d; } //打印CRSet对象中的数据 public static void print(CRSet cr) throws Exception{ if(cr!=null&&cr.getData().size()>0){ for(int i=0;i<cr.GetRowCount();i++) for(int j=0;j<cr.GetColumnCount();j++){ System.out.println("CRSet["+i+","+j+"]="+cr.GetValue(i, j)); } } } }
public CRSet(){}
public CRSet(int cols) throws Exception{
if(cols <= 0 || cols>=1024) { throw new Exception("SRVC009T:Illegal range of column or row."+cols); } m_Cols = cols; m_Rows = 0;
}
public int AddRow() { for(int i=0; i<m_Cols; i++) { m_Data.add(""); } return m_Rows++; } public void SetValue(int row, int col, String value) throws Exception { if(row >= m_Rows || col >= m_Cols) { throw new Exception("SRVC009T:Illegal range of column or row." + row + "," + col); } m_Data.set(row*m_Cols+col,value); } public String GetValue(int row, int col) throws Exception { if(row >= m_Rows || col >= m_Cols) { throw new Exception("SRVC009T:Illegal range of column or row." + row + "," + col); }
return (String)m_Data.elementAt(row*m_Cols+col); } public Vector getData(){ return m_Data; }
public Iterator iterator() { return m_Data.iterator(); }
抱歉!评论已关闭.