dictionary_finacialxmlbean.java
来自「java开发的办公系统 1.系统管理 (地区管理,部门管理,菜单管理,用户管理」· Java 代码 · 共 691 行 · 第 1/2 页
JAVA
691 行
} } } catch(Exception e){ System.err.println(e+"error"); } finally{ try{ if(fi!=null) fi.close(); if(fw!=null) fw.close(); } catch(Exception e){ e.printStackTrace(); } } return xmllist; } public Dictionary_finacialItem findXml(String id){ FileInputStream fi = null; FileWriter fw=null; Dictionary_finacialItem item = null; try{ fi = new FileInputStream(path); item = new Dictionary_finacialItem(); SAXBuilder sb = new SAXBuilder(); Document doc = sb.build(fi); Element root = doc.getRootElement(); //obtain root node List list = root.getChildren(); //obtain child of root node Element element =null; for(int i=0;i<list.size();i++){ element = (Element)list.get(i ); //obtain child node informaiton if(element.getChild("id").getText().trim().equals(id)){ item.setId(element.getChild("id").getText()); item.setPid(element.getChild("pid").getText()); item.setNodepath(element.getChild("nodepath").getText()); item.setName(element.getChild("name").getText()); item.setInstruction(element.getChild("instruction").getText()); return item; } } } catch(Exception e){ System.err.println(e+"error"); } finally{ try{ if(fi!=null) fi.close(); if(fw!=null) fw.close(); } catch(Exception e){ e.printStackTrace(); } } return item; } /** * remove element informaiton */ public boolean removeXmlItems(String[] ids){ boolean b=true; FileInputStream fi = null; FileWriter fw=null; try{ fi = new FileInputStream(path); SAXBuilder sb = new SAXBuilder(); Document doc = sb.build(fi); Element root = doc.getRootElement(); Element element =null; List list = root.getChildren(); for(int i=ids.length-1;i>=0;i--){ for(int j=list.size()-1;j>=0;j--){; element = (Element)list.get(j); if(element.getChild("id").getText().trim().equals(ids[i])){ list.remove(j); break; } } } XMLOutputter outer=new XMLOutputter(); fw=new FileWriter(path); Format fm=Format.getPrettyFormat(); fm.setEncoding("gb2312"); outer.setFormat(fm); outer.output(doc,fw); outer.output(doc,System.out); } catch(Exception e){ System.err.println(e+"error"); b=false; } finally{ try{ if(fi!=null) fi.close(); if(fw!=null) fw.close(); } catch(Exception e){ e.printStackTrace(); } } return b; } public boolean removeXmlItem(String id){ boolean b=true; FileInputStream fi = null; FileWriter fw=null; try{ fi = new FileInputStream(path); SAXBuilder sb = new SAXBuilder(); Document doc = sb.build(fi); Element root = doc.getRootElement(); List list = root.getChildren(); Element element =null; Dictionary_finacialItem item =null; for(int i=0;i<list.size();i++){ element = (Element)list.get(i); if(element.getChild("id").getText().trim().equals(id)){ list.remove(i); break; } } XMLOutputter outer=new XMLOutputter(); fw=new FileWriter(path); Format fm=Format.getPrettyFormat(); fm.setEncoding("gb2312"); outer.setFormat(fm); outer.output(doc,fw); outer.output(doc,System.out); } catch(Exception e){ System.err.println(e+"error"); b=false; } finally{ try{ if(fi!=null) fi.close(); if(fw!=null) fw.close(); } catch(Exception e){ e.printStackTrace(); } } return b; } /** * add a xml information */ public boolean addXmlItem(Dictionary_finacialItem item){ FileInputStream fi = null; FileWriter fw=null; boolean b=true; try{ fi = new FileInputStream(path); SAXBuilder sb = new SAXBuilder(); Document doc = sb.build(fi); Element root = doc.getRootElement(); List list = root.getChildren(); Element element =null; Text newtext; Element row= new Element("row"); Element id= new Element("id"); id.setText(item.getId()); row.addContent(id); Element pid= new Element("pid"); pid.setText(item.getPid()); row.addContent(pid); Element nodepath= new Element("nodepath"); nodepath.setText(item.getNodepath()); row.addContent(nodepath); Element name= new Element("name"); name.setText(item.getName()); row.addContent(name); Element instruction= new Element("instruction"); instruction.setText(item.getInstruction()); row.addContent(instruction); list.add(row); XMLOutputter outer=new XMLOutputter(); fw=new FileWriter(path); Format fm=Format.getPrettyFormat(); fm.setEncoding("gb2312"); outer.setFormat(fm); outer.output(doc,fw); outer.output(doc,System.out); } catch(Exception e){ System.err.println(e+"error"); b=false; } finally{ try{ if(fi!=null) fi.close(); if(fw!=null) fw.close(); } catch(Exception e){ e.printStackTrace(); } } return b; } /** * add more information **/ public boolean addXmlItems(ArrayList xmlList){ FileInputStream fi = null; FileWriter fw=null; boolean b=true; try{ fi = new FileInputStream(path); SAXBuilder sb = new SAXBuilder(); Document doc = sb.build(fi); Element root = doc.getRootElement(); List list = root.getChildren(); for(int i=0;i<xmlList.size();i++){ Dictionary_finacialItem item=(Dictionary_finacialItem)xmlList.get(i); Element element =null; Text newtext; Element row= new Element("row"); Element id= new Element("id"); id.setText(item.getId()); row.addContent(id); Element pid= new Element("pid"); pid.setText(item.getPid()); row.addContent(pid); Element nodepath= new Element("nodepath"); nodepath.setText(item.getNodepath()); row.addContent(nodepath); Element name= new Element("name"); name.setText(item.getName()); row.addContent(name); Element instruction= new Element("instruction"); instruction.setText(item.getInstruction()); row.addContent(instruction); list.add(row); } XMLOutputter outer=new XMLOutputter(); fw=new FileWriter(path); Format fm=Format.getPrettyFormat(); fm.setEncoding("gb2312"); outer.setFormat(fm); outer.output(doc,fw); outer.output(doc,System.out); } catch(Exception e){ System.err.println(e+"error"); b=false; } finally{ try{ if(fi!=null) fi.close(); if(fw!=null) fw.close(); } catch(Exception e){ e.printStackTrace(); } } return b; } /** * update xml information */ public boolean updateXmlItem(Dictionary_finacialItem item){ FileInputStream fi = null; FileWriter fw=null; try{ fi = new FileInputStream(path); SAXBuilder sb = new SAXBuilder(); Document doc = sb.build(fi); Element root = doc.getRootElement(); List list = root.getChildren(); for(int i=0;i<list.size();i++){ Element row=(Element)list.get(i); Element index= row.getChild("id"); if(index.getText().trim().equals(item.getId().trim())){ Element id= row.getChild("id"); id.setText(item.getId_no()); Element pid= row.getChild("pid"); pid.setText(item.getPid()); Element nodepath= row.getChild("nodepath"); nodepath.setText(item.getNodepath()); Element name= row.getChild("name"); name.setText(item.getName()); Element instruction= row.getChild("instruction"); instruction.setText(item.getInstruction()); XMLOutputter outer=new XMLOutputter(); fw=new FileWriter(path); Format fm=Format.getPrettyFormat(); fm.setEncoding("gb2312"); outer.setFormat(fm); outer.output(doc,fw); outer.output(doc,System.out); } } return true; } catch(Exception e){ System.err.println(e+"error"); return false; } finally{ try{ if(fi!=null) fi.close(); if(fw!=null) fw.close(); } catch(Exception e){ e.printStackTrace(); } } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?