zoukankan      html  css  js  c++  java
  • 读取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);
        }
    }                                                                                                                                                                            
  • 相关阅读:
    python爬虫实例——爬取歌单
    第一次接触稍大一点的项目有感——规范
    Ajax学习——ajax提交目的是返回刷新页面某个位置的内容
    C++ STL(标准模板库)的学习了解
    各高级编程语言分类分析
    ubuntu安装后中出现如下启动报错的错误
    解决GitHub下载慢的问题
    caffe的CPU编译需要更改的地方
    拐点处选择聚类K值
    python处理大规模数据时,出现memory
  • 原文地址:https://www.cnblogs.com/zhangchenglzhao/p/3028586.html
Copyright © 2011-2022 走看看