Database department data Generation XML tree

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.