网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > Java
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.Java远程方法调用(5).
.怎 样 在APPLET 中 发EMAIL.
.Java正则表达式详解(中).
.关于WebWork2中的中文问题 选择自.
.Java EE6提案的两大主题:拓展性.
.XSLT轻松入门第一章:XSLT概念.
.Java页面计数器.
.使用SWT开发用户图形界面.
.用Reflection实现Visitor模式.
.Java世界的Ruby.
.MVC 设计模式:将 Web 应用分三层.
.戏说java设计模式中的命令模式.
.谈模式(Singleton Pattern)的变形.
.定义Lucene 1.3 用到的索引文件格.
.J2ME学习笔记(2)—平台体系结构详.
.全面实践JNDI技术.
.经典收藏:J2ME Game的开发笔记.
.gwt和echo2的对比.
.在 Java 应用程序中创建图像.
.Java在软件开发中可能出现的几个.

Java、XML与数据库编程实践 (二)

发表日期:2008-1-5



  文件DbXMLParser.Java封装了对xml文件的操作。
  
  import javax.xml.parsers.*;
  
  import org.w3c.dom.*;
  
  import org.xml.sax.*;
  
  import java.io.*;
  
  public class DbXmlParser
  
  {
  
    static String xmlfile;
  
    public DbXmlParser(String filename)
  
    {
  
      xmlfile=filename;
  
    }
  
    public static Element loadDocument()
  
    {
  
      try
  
      {
  
        //工厂
  
        DocumentBuilderFactory dcfactory=DocumentBuilderFactory.newInstance();
  
        //文档构造器
  
        DocumentBuilder db=dcfactory.newDocumentBuilder();
  
        //构造的文档
  
        Document doc=db.parse(xmlfile);
  
        //根元素
  
        Element root=doc.getDocumentElement();
  
        return root;
  
        }catch( ParserConfigurationException e){
  
        System.out.println("ParserConfigurationException");
  
        e.printStackTrace();
  
      }catch(IOException e)   {
  
        System.out.println("IOException ");
  
        e.printStackTrace();
  
      }catch(SAXException e)   {
  
        System.out.println("SAXException ");
  
        e.printStackTrace();
  
      }catch(Exception e) {
  
        e.printStackTrace();
  
      }
  
      return null;
  
    }
  
    public ConnPara getSource()
  
    {
  
      Element root=loadDocument();
  
      if( root==null) { return null;  }
  
      NodeList nodes=root.getElementsByTagName("source");
  
      if(nodes.getLength()>0)
  
      {   
  
        Node node=nodes.item(0);
  
        String connclass=getChildElementValue(node,"class");
  
        String url=getChildElementValue(node,"url");
  
        String username=getChildElementValue(node,"user");
  
        String passWord=getChildElementValue(node,"password");
  
        return new ConnPara(connclass,url,username,password);
  
      }
  
      return null;   
  
    } 
  
    public ConnPara getDest()
  
    {
  
      Element root=loadDocument();
  
      if( root==null) return null;
  
      NodeList nodes=root.getElementsByTagName("dest");
  
      if(nodes.getLength()>0)
  
      {   
  
        Node node=nodes.item(0);
  
        String connclass=getChildElementValue(node,"class");
  
        String url=getChildElementValue(node,"url");
  
        String username=getChildElementValue(node,"user");
  
        String password=getChildElementValue(node,"password");
  
        return new ConnPara(connclass,url,username,password);
  
      }
  
      return null;   
  
    }
  
    //得到子元素的值
  
    private String getChildElementValue(Node node,String suBTagName)
  
    {
  
        String returnString = "";
  
        if(node !
上一篇:Java、XML与数据库编程实践 (三) 人气:511
下一篇:Java与XML联合编程之DOM篇 人气:590
浏览全部Java的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐