sax解析+拼接字符串

 

用的是 public Map<String , List<String>> map = new HashMap<String ,List<String>>();
HashMap 是无序的,导致数据的顺序总是变换,后来修改成了 public Map<String , List<String>> map = new LinkedHashMap<String ,List<String>>();
其实吧,也可以用ListOrderedMap

 

 

 

 

 

########################################Action

package com.ths.projects.xzxk.web.syssb.wysb;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONObject;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springside.modules.web.struts2.Struts2Utils;

import com.ths.platform.custom.action.BaseAction;

 

public class WysbAction extends BaseAction {
 private static final Logger log = LoggerFactory.getLogger( WysbAction.class );
 
 public Map<String , List<String>> map = new LinkedHashMap<String ,List<String>>();
 public List<String> list =null;
 private String res = "";
 
 /**
 * 我要申报主页面
 */
 public String mainlist() {
  
  //创建解析器
  SAXReader xmlReader = new SAXReader();
  //创建集合类型
  
  try {
   //获取xml路径
   Document doc = xmlReader.read("D:/wwsb.xml");
   //把xml加载到document对象中
   Element myRoot = doc.getRootElement();
   //按照树的思想进行解析
   Element onePerson = myRoot.element("table");
   //得到下一级元素集合
   List<Element> oneElements = onePerson.elements();
   //循环遍历
   
   for (int i = 0; i < oneElements.size(); i++) {
    //获取table的key ,value
    Element e = oneElements.get(i);
   // System.out.println(e);
    //获取cell的key ,value
    List<Element> oneElement2 = e.elements();
    list = new ArrayList<String>();
    for (int j = 0; j < oneElement2.size(); j++) {
     Element e2 = oneElement2.get(j);
     list.add(e2.attributeValue("key"));
     list.add(e2.attributeValue("name"));
     list.add(e2.attributeValue("url"));
     list.add(e2.attributeValue("disable"));
    }
    map.put(e.attributeValue("title"), list);
   }
  } catch (DocumentException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  //ss<row title="建设项目环境影响评价文件审批1">
  for (String ss : map.keySet()) {
   String tab = "<div class='button-div'><div class='list-title'><span><img src='../../util/xzxk/images/title.png'/></span>"+ss+"</div><ul>";
   //遍历出,cell中的value
   List<String> list2 = map.get(ss);
   //System.out.println(ss);
   System.out.println("打印出cell中的value"+list2);
   for (int i = 0; i < 15; i++) {
    tab += "<li><span>"+list2.get(i+1)+"</span></li>";
    i+=3;
   }
   tab += "<div class='clearfloat'></div></ul></div>";
   res += tab;
  }
  return "wysbmain_list";
 }

 public Map<String, List<String>> getMap() {
  return map;
 }

 public void setMap(Map<String, List<String>> map) {
  this.map = map;
 }

 public List<String> getList() {
  return list;
 }

 public void setList(List<String> list) {
  this.list = list;
 }

 public String getRes() {
  return res;
 }

 public void setRes(String res) {
  this.res = res;
 }
 
 
}
*************************************xml

<?xml version="1.0" encoding="utf-8"?>

<root>
  <show time_step="" time_unit="">
    <param>
     <replace format="request" name="companyid" place="companyid"/>
     <replace format="request" name="id" place="id"/>
     <replace format="request" name="belongsdate" place="belongsdate"/>
     <replace format="request" name="intact" place="intact"/>
        <replace format="sql"     name="" datasource=""  place="newid"/>
    </param>
  </show>
  <table>
     <row title="建设项目环境影响评价文件审批1">
    <cell  key="card11"  name="办事指南" url="../../syssb/wysb/hpsp/hpsp!guid.action" disable="true"/>
    <cell  key="card12"  name="表格下载" url="../../syssb/wysb/hpsp/hpsp!apply.action"  disable="true"/> 
    <cell  key="card13"  name="在线申报" url="../../syssb/wysb/hpsp/hpsp!regist.action"  disable="true"/>
    <cell key="card14" name="状态查询" url="../../syssb/wysb/hpsp/hpsp!registCon.action" disable="true" /> 
   </row>
   <row title="建设项目环境影响评价文件审批2">
    <cell  key="card21"  name="办事指南" url="../../syssb/wysb/hpsp/hpsp!guid.action" disable="true"/>
    <cell  key="card22"  name="表格下载" url="../../syssb/wysb/hpsp/hpsp!apply.action"  disable="true"/>
    <cell  key="card23"  name="在线申报" url="../../syssb/wysb/hpsp/hpsp!regist.action"  disable="true"/>
    <cell  key="card24"  name="状态查询" url="../../syssb/wysb/hpsp/hpsp!registCon.action"  disable="true"/>
   </row>
   <row title="建设项目环境影响评价文件审批3">
    <cell  key="card31"  name="办事指南" url="../../syssb/wysb/hpsp/hpsp!guid.action" disable="true"/>
    <cell  key="card32"  name="表格下载" url="../../syssb/wysb/hpsp/hpsp!apply.action"  disable="true"/>
    <cell  key="card33"  name="在线申报" url="../../syssb/wysb/hpsp/hpsp!regist.action"  disable="true"/>
    <cell  key="card34"  name="状态查询" url="../../syssb/wysb/hpsp/hpsp!registCon.action"  disable="true"/>
   </row>
  </table> 
</root>

***************************************************jsp

<%@page import="java.util.ArrayList"%>
<%@page import="org.dom4j.DocumentException"%>
<%@page import="java.util.List"%>
<%@page import="org.dom4j.Element"%>
<%@page import="org.dom4j.Document"%>
<%@page import="java.util.HashMap"%>
<%@page import="java.util.Map"%>
<%@page import="org.dom4j.io.SAXReader"%>
<%@page import="com.ths.projects.xzxk.web.syssb.wysb.WysbAction" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>办事指南</title>
<!--[if lte IE 7]>
<style>
.content { margin-right: -1px; }
ul.nav a { zoom: 1; }
</style>
<![endif]-->
<%@ include file="/thscommon/jsp/taglibsforform.jsp"%>
<link rel="stylesheet" type="text/css" href="${ctx }/util/xzxk/css/xzxk_style.css" />
<script type="text/javascript">
function zxtb(cardtype,nodeid,cursel){
 $("#state").val(nodeid);
 $("#cardtype").val(cardtype);
 $("#cursel").val(cursel);
 document.all.jumpform.action="${ctx}/common/itemcard/item-card!itemcardmain.action";
 document.all.jumpform.submit();
 //window.open('${ctx}/common/itemcard/item-card!itemcardmain.action?state=申报1&cardtype='+cardtype,'itemcardmain','height=600px,width=1100px,top=36px,left=100px,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,status=no');
}

</script>
</head>

<body>
 ${res}
 
<form action="" target="_blank" method="post"  id="jumpform" name="jumpform">
  <input name="state" id="state" type="hidden" value=""/>
  <input name="cardtype" id="cardtype" type="hidden" value=""/>
  <input name="cursel" id="cursel" type="hidden" value=""/>
</form>
</body>
</html>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值