Department Bean Main code
&NBSP;&NBSP;&NBSP;&NBSP;PRIVATE&NBSP;STRING&NBSP;DEPTNAME;//Department Name private string &NBSP;DEPTCODE;//Department Code private string fdeptcode;//Superior Department Code private string isleaf;//is the leaf department private List<Dep> children;//Sub-Department collection private string id;//department id //set how to get a child department public void setchildren (String fdeptcode) { if (Isleaf.equals ("1")) { }else{ List<Dep> listDep=new Arraylist<dep> (); dbconn db= New dbconn (); resultset rst= Null; string sql1= "select deptcode from comdept where fdeptcode=" + Fdeptcode+ "'"; try { rst=db.executequery (SQL1); while (Rst.next ()) { string depcode=rst.getstring ("Deptcode"); //Call construction method if DEP has sub-departments will also be placed under DEP dep dep=new dep (DEPcode); listdep.add (DEP); } } catch (sqlexception e) { // TODO Auto-generated catch block e.printstacktrace (); } this.children = listDep; } } //Construction Method &NBSP;&NBSP;&NBSP;&NBSP;PUBLIC&NBSP;DEP (String deptcode) { this.deptcode=deptcode; setall (Deptcode); setchildren (deptcode); }
Write a tree-type catalog code to XML
Public class writetoxml { static list<dep> listdep=new &NBSP;DEP ("0000"); //0000 for department root element root=documenthelper.createelement ("Dep"); document doc=documenthelper.createdocument (); Public void write (list<dep> listdep,element element) { for (DEP&NBSP;DEP:LISTDEP) { //Add node name for Department name Element menuElement = Element.addelement (Dep.getdeptname ()); //adding properties to a node Deptcode,value to department id attribute att=documenthelper.createattribute (menuelement, "Deptcode", Dep.getDeptcode ()); Menuelement.add (ATT); if (Dep.getchildren ()!=null&&dep.getchildren (). Size () >0) { write ( Dep.getchildren (), menuelement); } } } public void writeall (String path) { //all nodes are written to the root node write (listdep,root); try{ xmlwriter xmlwriter=new XMLWriter (New filewriter (new file (path))); doc.add (Root); Xmlwriter.write (DOC); xmlwriter.close () ; }catch (ioexception e) { e.printstacktrace (); } } public static void main (String[] args) { writetoxml t=new writetoxml (); t.writeall ("E://test.xml"); }}
Finally, I probably know how the XML is written ... The next step is to create an HTML tree-shaped directory of XML.
This article is from the "Java Monk" blog, please be sure to keep this source http://fly2017.blog.51cto.com/5237541/1707532
Database department data Generation XML tree