package src.treeXmltoExcel;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
public class xmlReader{
public void LoadFromXml(String treepath,String mappath){
map = new HashMap();
commandmap = new HashMap();
SAXBuilder sbcommand = new SAXBuilder();
SAXBuilder sbtree = new SAXBuilder();
try{
Document doccommand = sbcommand.build(mappath);
Element rootcommand = doccommand.getRootElement();
Loadcommandchild(rootcommand);
//ArrayList list =(ArrayList)rootcommand.getChildren("Command");
/** for(Iterator iter = rootcommand.getChildren().iterator(); iter.hasNext(); ){
Element el = (Element) iter.next();
if(el.getChildren()!=null){
Loadcommandchild(el);
}
else{
String Code = el.getAttributeValue("Code");
String MocClass = el.getAttributeValue("MocClass");
String MocMethod = el.getAttributeValue("MocMethod");
commandmap.put(Code, Code+"-"+MocClass+"-"+MocMethod);
}
}**/
commandmap.size();
Document dotree = sbtree.build(treepath);
Element roottree = dotree.getRootElement();
Loadtreechild(roottree);
//ArrayList listtree=(ArrayList)roottree.getChildren("command");
/** for(Iterator it =roottree.getChildren().iterator();it.hasNext();){
Element el1 = (Element) it.next();
if(commandmap.containsKey(el1.getAttributeValue("code"))){
String name = el1.getAttributeValue("name");
String note = el1.getAttributeValue("note");
String notee = el1.getAttributeValue("notee");
String temp=commandmap.get(el1.getAttributeValue("code")).toString();
//commandmap.remove(el1.getAttributeValue("code"));
map.put(el1.getAttributeValue("code"), temp+"-"+name+"-"+note+"-"+notee);
}
}**/
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void Loadcommandchild(Element e){
for(Iterator iter = e.getChildren().iterator(); iter.hasNext(); ){
Element el = (Element) iter.next();
Loadcommandchild(el);
String Code = el.getAttributeValue("Code");
String MocClass = el.getAttributeValue("MocClass");
String MocMethod = el.getAttributeValue("MocMethod");
commandmap.put(Code, Code+"="+MocClass+"="+MocMethod);
}
}
public void Loadtreechild(Element e){
for(Iterator iter = e.getChildren().iterator(); iter.hasNext(); ){
Element el = (Element) iter.next();
Loadtreechild(el);
if(commandmap.containsKey(el.getAttributeValue("code"))){
String name = el.getAttributeValue("name");
String note = el.getAttributeValue("note");
String notee = el.getAttributeValue("notee");
String temp=commandmap.get(el.getAttributeValue("code")).toString();
//commandmap.remove(el1.getAttributeValue("code"));
map.put(el.getAttributeValue("code"), temp+"="+name+"="+note+"="+notee);
}
}
}
public HashMap getMap(){
if(map==null){
map = new HashMap();
}
return map;
}
private HashMap commandmap;
private HashMap map;
}
将两个XML文件部分内容读出写入EXCEL
4星 · 超过85%的资源 需积分: 9 66 浏览量
2008-04-30
17:05:40
上传
评论
收藏 53KB RAR 举报
kocs2002
- 粉丝: 0
- 资源: 4