最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
XML配置文件的读取(sax)
时间:2008-01-12 编辑:简简单单 来源:一聚教程网
在最近的一个MIS项目中,为了避免硬编码,我需要把一些配置信息写在一个配置文件中.考虑到是J2EE项目,J2EE的配置文件
好像都是xml文件了,再用传统ini文件是不是有点落伍了?
ok,就用xml做配置文件吧.
我的配置文件reportenv.xml如下,比较简单:
现在的问题是我用什么来读取配置信息?
现在流行的是dom4j和sax,我以前一直用dom4j.可是weblogic workshop自带的是sax,我又不想再引入包了,于是就是sax吧.
第一步:ConfigParser.java
/*
* Create Date: 2005-6-13
* Create By: 板桥里人
* purpose:xml配置文件属性读取器
*/
package com.infoearth.report;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.SAXException;
import java.util.Properties;
public class ConfigParser extends DefaultHandler {
////定义一个Properties 用来存放属性值
private Properties props;
private String currentSet;
private String currentName;
private StringBuffer currentValue = new StringBuffer();
//构建器初始化props
public ConfigParser() {
this.props = new Properties();
}
public Properties getProps() {
return this.props;
}
//定义开始解析元素的方法. 这里是将
public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException {
currentValue.delete(0, currentValue.length());
-
下一个: Jsp中使用xmlhttp进行数据交互~
相关文章
- SpringBoot测试配置属性与web启动环境解析 10-24
- vue中将el-switch值true、false改为number类型的1和0解析 10-24
- Vue中的路由配置项meta使用解读 10-24
- SpringBoot自定义bean绑定解析 10-24
- SpringBoot常用计量与bean属性校验和进制数据转换规则解析 10-24
- 工厂方法在Spring框架中的运用介绍 10-24