一杯清茶

          統(tǒng)計(jì)

          留言簿

          Oracle SQL/PLSQL

          PowerDesigner教程系列

          Struts2.0

          web開發(fā)

          三人行

          從事RCP開發(fā)的同行

          工作流和權(quán)限設(shè)置

          閱讀排行榜

          評(píng)論排行榜

          使用dom4j讀取xml文檔,并修改文檔

          自用文檔,請(qǐng)不要轉(zhuǎn)載!


          public void prot() throws Exception{   
                      try {
                          String path=FileLocator.toFileURL(Platform.getBundle(AppConn.APPLICATION_ID).getEntry("")).getPath()
                                                 .toString()+"src/hibernate.cfg.xml";
                          File cfgFile=new File(path);
                          SAXReader reader=new SAXReader();           
                          reader.setEntityResolver(new EntityResolver()      
                          {      
                              public InputSource resolveEntity(String publicId,      
                                      String systemId)      
                              {      
                                  if (publicId.equals("-//Hibernate/Hibernate Configuration DTD 3.0//EN"))      
                                  {      
                                      InputStream in = getClass().getResourceAsStream(      
                                              "/hibernate-configuration-3.0.dtd");      
                                      return new InputSource(in);      
                                  }      
                                  return null;      
                              }      
                          });            
                          Document document=null;
                          try {
                              document = reader.read(cfgFile);
                          } catch (DocumentException e) {
                              // TODO Auto-generated catch block
                              e.printStackTrace();
                          }
                          Element root=document.getRootElement();
                          List list=root.selectNodes("http://property");
                          Iterator it=list.iterator();
                          while(it.hasNext()){
                              Element nextelement=(Element)it.next();
                              String  text=nextelement.attributeValue("name");
                              if(text.equals("connection.username")){
                                      nextelement.setText("");                                                               
                              }
                              if(text.equals("connection.password")){                       
                                      nextelement.setText("");                   
                              }
                              if(text.equals("connection.url")){
                                      nextelement.setText("");                                       
                              }               
                          }               
                              XMLWriter output=new XMLWriter(new FileWriter(cfgFile),OutputFormat.createPrettyPrint());
                              output.write(document);
                              output.flush();
                              output.close();
                     
                      } catch (HibernateException e) {
                          // TODO Auto-generated catch block
                          e.printStackTrace();
                      }    
                     
                  }

          posted on 2008-04-23 15:06 一杯清茶 閱讀(292) 評(píng)論(0)  編輯  收藏 所屬分類: Hibernate

          主站蜘蛛池模板: 玛沁县| 获嘉县| 萝北县| 长顺县| 雷山县| 绥芬河市| 佛学| 上思县| 安塞县| 正镶白旗| 栖霞市| 阳山县| 陇南市| 莲花县| 镇江市| 汪清县| 额尔古纳市| 桓台县| 拜泉县| 朔州市| 客服| 屯昌县| 济源市| 肥东县| 琼中| 天祝| 敦煌市| 潮安县| 泰和县| 城市| 潜江市| 同德县| 鄂尔多斯市| 大同县| 龙南县| 临朐县| 云阳县| 凌云县| 精河县| 绥化市| 大庆市|