有人会jdom吗?

stone18 2005-11-07 05:41:12
<?xml version="1.0" encoding="GBK"?>
<configCon>
<ConUrl id="21" >
<title name="欢迎访问 STONE 个人网站"/>
<lefttopcon name="inc/leftTopContact.jsp"/>
<leftnextcon name="inc/leftNextViewCnt.jsp?nid=21"/>
<leftthrcon name="inc/leftThrContent.jsp?lid=35&rid=21"/>
<righttopcon name="inc/rightTopMenu.jsp?nid=12" />
<rightnextcon name="inc/rightNextMenu.jsp?nid=5" />
<rightthrcon name="inc/rightThrContent.jsp"/>
<listId id="1">16,18,19,20,22,23,24,25</listId>
<listId id="2">17,18,19,20,22,23,24,25</listId>


</ConUrl>
<ConUrl id="5" >
<title name="技术文摘"/>
<lefttopcon name="inc/leftTopContact.jsp"/>
<leftnextcon name="inc/leftNextViewCnt.jsp?nid=21"/>
<leftthrcon name="inc/leftThrContent.jsp?lid=35&rid=21"/>
<righttopcon name="inc/rightTopMenu.jsp?nid=12" />
<rightnextcon name="inc/rightNextMenu.jsp?nid=5" />
<rightthrcon name="inc/rightThrContent.jsp?nid=5,6,7,9,27,28" />
<listId id="1">18,18,19,20,22,23,24,25</listId>
<listId id="2">19,18,19,20,22,23,24,25</listId>
</ConUrl>



</configCon>
原来程序:
package com.ionglobal.init;

import com.ionglobal.db.Category;
import com.ionglobal.db.DBI;
import com.ionglobal.lib.SysException;
import java.io.FileWriter;
import java.net.URL;
import java.util.List;
import java.util.Iterator;
import java.util.Hashtable;
import java.util.Vector;
import org.apache.log4j.Logger;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
import org.jdom.xpath.XPath;

public class ConfigConApp {
private URL xmlPath;
private Element elmRoot;
private Document doc;
private static Logger log;
private static ConfigConApp instance = null;
private static Vector bbsCategory;

static {
log = Logger.getLogger(com.ionglobal.init.ConfigConApp.class);
}

public ConfigConApp() throws SysException {
try {
xmlPath = com.ionglobal.init.ConfigConApp.class.getResource(
"/conConfig.xml");
SAXBuilder sb = new SAXBuilder();
doc = sb.build(xmlPath);
elmRoot = doc.getRootElement();
} catch (Exception e) {
log.error("conConfig()" + e.getMessage());
} finally {
}
}


/*public Hashtable getConfigCon() {
Hashtable number = new Hashtable();
ConfigCon newConfigCon;
try {
List list = XPath.selectNodes(elmRoot, "/configCon/ConUrl");
for (int i = 0; i < list.size(); i++) {
Element elm = (Element) list.get(i);
newConfigCon = new ConfigCon();
newConfigCon.setId(elm.getAttributeValue("id"));
newConfigCon.setTitle(elm.getAttributeValue("title"));
newConfigCon.setLefttopcon(elm.getAttributeValue("lefttopcon"));
newConfigCon.setLeftnextcon(elm.getAttributeValue("leftnextcon"));
newConfigCon.setLeftthrcon(elm.getAttributeValue("leftthrcon"));
newConfigCon.setRighttopcon(elm.getAttributeValue("righttopcon"));
newConfigCon.setRightnextcon(elm.getAttributeValue(
"rightnextcon"));
newConfigCon.setRightthrcon(elm.getAttributeValue("rightthrcon"));
number.put(elm.getAttributeValue("id"), newConfigCon);
List lis=elm.getChildren();
System.out.println(elm.getName());
for (int k = 0; k < lis.size(); k++) {
Element elmb = (Element) lis.get(k);
System.out.println(elmb.getName()+"-"+elmb.getValue());
}
}

} catch (Exception e) {
log.error(e);
}
return number;
}
*/
public Hashtable getConfigCon() {
Hashtable number = new Hashtable();
ConfigCon newConfigCon;
try {
List list = XPath.selectNodes(elmRoot, "/configCon/ConUrl");
for (int i = 0; i < list.size(); i++) {
Element elm = (Element) list.get(i);

newConfigCon = new ConfigCon();
newConfigCon.setId(elm.getAttributeValue("id"));
newConfigCon.setTitle(elm.getChild("title").getAttributeValue("name"));
newConfigCon.setLefttopcon(elm.getChild("lefttopcon").getAttributeValue("name"));
newConfigCon.setLeftnextcon(elm.getChild("leftnextcon").getAttributeValue("name"));
newConfigCon.setLeftthrcon(elm.getChild("leftthrcon").getAttributeValue("name"));
newConfigCon.setRighttopcon(elm.getChild("righttopcon").getAttributeValue("name"));
newConfigCon.setRightnextcon(elm.getChild("rightnextcon").getAttributeValue("name"));
newConfigCon.setRightthrcon(elm.getChild("rightthrcon").getAttributeValue("name"));
}

} catch (Exception e) {
System.out.print(e);
log.error("getConfigCon()" + e.getMessage());
}
return number;
}

public static void main(String aegs[]) throws SysException{
ConfigConApp con=new ConfigConApp();
Hashtable num= con.getConfigCon();
System.out.println("num="+num.size());


}
}
如何在for里面读取listid的内容,请帮改改
...全文
100 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧