• 读取xml 文档


    例子:

      

    //先new xml  读取
    private static final String CONFIG_PATH="configuration.xml";
    private static final XmlReader xml=new XmlReader(CONFIG_PATH);
    
    public List<CheckBean> jobsel=Constant.rzPerSelJob;
    public static final List<CheckBean> rzPerSelJob=new ArrayList<CheckBean>();
     //静态赋值
    static{
          for(String s:xml.getStringArray("rzPer.select.job")){
              String[] t=s.split(":");  
              rzPerSelDegree.add(new CheckBean(1, t[0],t[1], "degree-sel"));
        }
           
    }    ///
    
    
        xml 文档写法
    
    
    <?xml version="1.0" encoding="GB2312"?>
    <configuration>
    
                     <rzPer>
                            <select>
                                 <job>01:学习</job>
                                 <job>02:企事业单位职工</job>
                    <job>03:农民</job>
                    <job>04:个体工商户</job>
                    <job>05:学生</job>
                      <job>06:无业</job>
                    <job>07:其他</job>
                                 </select>
                      </rzPer>
             
    </configuration>        
    
    
    
    //xml  bean 
    
    package com.yuhong.see.util;
    
    import org.apache.commons.configuration.Configuration;
    import org.apache.commons.configuration.ConfigurationException;
    import org.apache.commons.configuration.XMLConfiguration;
    
    public class XmlReader {
        private String  CONFIG_PATH;
        
        private static Configuration config; 
        
        public XmlReader(String ConfigPath){
            this.CONFIG_PATH=ConfigPath;
            this.Configure();
        }
        
        public void Configure(){
            try {
                config = new XMLConfiguration(CONFIG_PATH);
            } catch (ConfigurationException e) {
                e.printStackTrace();
            }
        }
    
        public String getString(String infoLabel) {
            return config.getString(infoLabel);
        }
        
        public boolean getBoolean(String infoLabel) {
            return config.getBoolean(infoLabel);
        }
        
        public int getInt(String infoLabel) {
            return config.getInt(infoLabel);
        }
        
        public double getDouble(String infoLabel) {
            return config.getDouble(infoLabel);
        }
        
        public String[] getStringArray(String infoLabel) {
            return config.getStringArray(infoLabel);
        }
    }                                                                                                                                                                            
  • 相关阅读:
    uva 11997
    【USACO 3.1.1】最短网络
    【USACO 2.4.5】分数化小数
    【USACO 2.4.4】回家
    【USACO 2.4.3】牛的旅行
    【USACO 2.4.2】穿越栅栏
    【USACO 2.4.1】两只塔姆沃斯牛
    【USACO 2.3.5】控制公司
    【USACO 2.3.4】货币系统
    【USACO 2.3.3】零数列
  • 原文地址:https://www.cnblogs.com/zhangchenglzhao/p/3028586.html
Copyright © 2020-2023  润新知