zoukankan      html  css  js  c++  java
  • JDOM操作xml文件


    import java.io.IOException;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Map;

    import org.apache.xpath.XPath;
    import org.jaxen.JaxenException;
    import org.jdom.input.SAXBuilder;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.NodeList;

    public class GlobalConfigure {

     private static GlobalConfigure instance=new GlobalConfigure();
     
     private Element rootElt;
     
     private GlobalConfigure() throws IOException
     {
      SAXBuilder sb=new SAXBuilder();
            try {
       Document doc=sb.build(Thread.currentThread().getContextClassLoader()
         .getResourceAsStream("global-configure.xml"));
                //得到元素根节点
       this.rootElt=doc.getDocumentElement();
       //得到子节点
                //NodeList nodlist=rootElt.getChildNodes();
                initJdbcInfo();
            } catch (Exception e) {
       e.printStackTrace();
      }
     }
     
     public static GlobalConfigure getInstance()
     {
      return instance;
     }
     
     private void initJdbcInfo()
     {
      try {
       Element element = XPath.selectSingleNode(rootElt,
         "//sys-configure/jdbc-info/driver-class-name");
          //System.out.println(element.getTextContent());
      } catch (JaxenException e) {
       e.printStackTrace();
      }   
     }
     
     private void initBean()
     {
      List beanList=XPath.selectNodes(rootElt,"//sys-configure/beans");
      for(Iterator iter=beanList.iterator();iter.hasNext();)
      {
       Element beanElt=(Element)iter.next();
       String id=beanElt.getAttribute("id");
          String className=beanElt.getAttribute("class");
          //System.out.println("id="+id);
          //System.out.println("name="+className);
          Object obj=Class.forName(className).newInstance();
          Map beanMap=new HashMap();
          beanMap.put(id, className);
      }
     }
     
     public static void main(String args[])
     {
      GlobalConfigure.getInstance();
     }
    }

  • 相关阅读:
    luogu 1726 上白泽惠音
    POJ1419 Graph Coloring(最大独立集)(最大团)
    POJ2284 That Nice Euler Circuit (欧拉公式)(计算几何 线段相交问题)
    POJ 1966 Cable TV Network(顶点连通度的求解)
    POJ 1523 SPF(寻找关节点)
    Dwarves (有向图判环)
    POJ 3041 Asteroids(最小点覆盖集)
    POJ 1043 What's In A Name?(唯一的最大匹配方法)
    POJ Girls and Boys (最大独立点集)
    Jewelry Exhibition(最小点覆盖集)
  • 原文地址:https://www.cnblogs.com/jinzhengquan/p/1959336.html
Copyright © 2011-2022 走看看