xml文件内容:
<?xml version="1.0" encoding="UTF-8"?>
<channels>
<channel switchTime="20080101000101" k="1.07" n="6" s="55" channelId="0404" channelName="xxxx.xxxx.xxx.cn"/>
<channel switchTime="20080301010101" k="1.07" n="6" s="55" channelId="0405" channelName="xxxx.xxxx.xxx.cn"/>
<channel switchTime="20080301010101" k="1.07" n="6" s="55" channelId="0406" channelName="xxxx.xxxx.xxx.cn"/>
<channel switchTime="20080301010101" k="1.07" n="6" s="55" channelId="0407" channelName="xxxx.xxxx.xxx.cn"/>
<channel switchTime="20080301010101" k="1.07" n="6" s="55" channelId="0408" channelName="xxxx.xxxx.xxx.cn"/>
<channel switchTime="20080301010101" k="1.07" n="6" s="55" channelId="0409" channelName="xxxx.xxxx.xxx.cn"/>
<channel switchTime="20080301010101" k="1.07" n="6" s="55" channelId="0433" channelName="xxxx.xxxx.xxx.cn"/>
<channel switchTime="20080301010101" k="1.07" n="6" s="55" channelId="0434" channelName="xxxx.xxxx.xxx.cn"/>
<channel switchTime="20080301010101" k="1.07" n="6" s="55" channelId="0437" channelName="xxxx.xxxx.xxx.cn"/>
<channel switchTime="20080301010101" k="1.07" n="6" s="55" channelId="0435" channelName="xxxx.xxxx.xxx.cn"/>
<channel switchTime="20080301010101" k="1.07" n="6" s="55" channelId="0438" channelName="xxxx.xxxx.xxx.cn"/>
<channel switchTime="20080301010101" k="1.07" n="6" s="55" channelId="0439" channelName="xxxx.xxxx.xxx.cn"/>
<channel switchTime="20080301010101" k="1.07" n="6" s="55" channelId="0440" channelName="xxxx.xxxx.xxx.cn"/>
</channels>
import org.apache.commons.digester.Digester;
Digester digester = new Digester();
//此方法作用是是否对XML文档进行DTD验证
digester.setValidating(false);
//addObjectCreate的作用是:当遇见channels元素的时候,产生一个java.util.ArrayList对象
digester.addObjectCreate("channels", "java.util.ArrayList");
//addSetProperties作用是:对channels元素所含的属性赋值(即下面channels/channel中的对象值)
digester.addSetProperties("channels");
//当遇见channels/channel元素的时候,产生一个com.chinacache.config.model.ChannelSwitch对象
digester.addObjectCreate("channels/channel","com.chinacache.config.model.ChannelSwitch");
//对channels/channel元素所含的属性赋值给ChannelSwitch对象
digester.addSetProperties("channels/channel");
//当再一次遇见 channels下的channel元素的时候,调用ArrayList类的add()方法,add:com.chinacache.config.model.ChannelSwitch对象
digester.addSetNext("channels/channel", "add","com.chinacache.config.model.ChannelSwitch");
调用:
try {
List channelList = (List) digester
.parse(ChannelSwitchInfoImpl.class
.getResourceAsStream(Constants.PATH_CHANNEL_SWITCH));
for (int i = 0; i < channelList.size(); i++) {
ChannelSwitch channelSwitch = (ChannelSwitch) channelList
.get(i);
this.channelSwitchs.put(channelSwitch.getChannelName(),
channelSwitch);
this.channelSwitchsSavedById.put(channelSwitch.getChannelId(),
channelSwitch);
}
} catch (IOException e) {
logger.error("load channelswitch.xml error.", e);
} catch (SAXException e) {
logger.error("load channelswitch.xml error.", e);
}
分享到:
相关推荐
commons-lang3.3.1.jar、Apache Commons包中的一个,包含了一些数据类型工具类,是java.lang.*的扩展。必须使用的jar包。为JRE5.0+的更好的版本所提供 Jar文件包含的类: META-INF/MANIFEST.MFMETA-INF/LICENSE....
commons-lang3.3.1.jar、Apache Commons包中的一个,包含了一些数据类型工具类,是java.lang.*的扩展。必须使用的jar包。为JRE5.0+的更好的版本所提供 Jar文件包含的类: META-INF/MANIFEST.MFMETA-INF/LICENSE....
org.apache.commons.commons-math3:3.6.1
import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods....
jar包分享,你懂的 com.springsource.org.apache.commons.io-1.4.0.jar
com.springsource.org.apache.commons.logging-1.1.1.jar
com.springsource.org.apache.commons.lang
com.springsource.org.apache.commons.logging-sources-1.1.1.jar
最新org.apache.commons.net..包完整、干净、实用
org.apache.commons.beanutils.jar
整个系统都没有错误,但是在发布运行后,控制台上却抛出了这样的异常: java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource
com.springsource.org.apache.commons.fileupload 自己打入本地Jar包即可
需要先 import org.apache.commons.lang3.StringUtils; /* 内含 common-lang3.jar commons-lang3-3.9-bin.zip commons-lang3-3.9-src.zip 使用说明.txt*/ public static String getClientIp(HttpServletRequest ...
org.apache.commons.lang jar包
org.apache.commons相关的所以jar包,包括commons-beanutils-1.8.0-bin.zip;commons-betwixt-0.8.zip;commons-cli-1.1.zip;commons-codec-1.3.zip;commons-collections-3.2.1-bin.zip;commons-digester-1.8.zip...
import org.apache.commons.beanutils.PropertyUtilsBean; import org.apache.commons.lang.StringUtils; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFCellStyle; ...
com.springsource.org.apache.commons.pool-sources-1.5.3.jar源码
org.apache.commons.lang所有包的集合,
解决经常遇到的The import org.apache.commons.codec cannot be resolved问题,只需导入文件中的commons-codec-1.11.jar就可以,如和导入包就不赘述了。
com.springsource.org.apache.commons.dbcp-sources-1.2.2.osgi.jar源码 jar包