jsp 动态树
Document document = DocumentHelper.createDocument(); Element root = document.addElement("node"); initDocument(node, root); OutputFormat format = OutputFormat.createPrettyPrint();// 创建格式化对象 format.setEncoding(encoding);// 设置字符编码 // format.setIndent(false); XMLWriter xmlWriter = new XMLWriter(outputStream, format);// 输出XML文档输出 xmlWriter.write(document); // xmlWriter.flush(); // xmlWriter.close();//此处不需要刷新或关闭流,全都交由外部程序控制 } public static void write(INode node, Writer writer, String encoding) throws Exception { node.setRootNode(true); Document document = DocumentHelper.createDocument(); Element root = document.addElement("node"); initDocument(node, root); OutputFormat format = OutputFormat.createPrettyPrint();// 创建格式化对象 format.setEncoding(encoding);// 设置字符编码 XMLWriter xmlWriter = new XMLWriter(writer, format);// 输出XML文档输出 xmlWriter.write(document); // xmlWriter.flush(); // xmlWriter.close();//此处不需要刷新或关闭流,全都交由外部程序控制 } private static void initDocument(INode node, Element menu) { String nodeId = node.getNodeId(); String nodeName = node.getNodeName(); String sequence = "" + node.getSequence(); String isRootNode = "" + node.isRootNode(); String isLeafNode = "" + node.isLeafNode(); String isFirstChildNode = "" + node.isFirstChildNode(); String isLastChildNode = "" + node.isLastChildNode(); String command = node.getCommand(); command = StringUtils.trimToBlank(command);// 只有comment返回值才有可能为null,因此要进行转换 menu.addAttribute("nodeId", nodeId); menu.addAttribute("nodeName", nodeName); menu.addAttribute("sequence", sequence); menu.addAttribute("rootNode", isRootNode); menu.addAttribute("leafNode", isLeafNode); menu.addAttribute("firstChildNode", isFirstChildNode); menu.addAttribute("lastChildNode", isLastChildNode); menu.addAttribute("command", command); if (null != node.getChildNodes() && 0 != node.getChildNodes().size()) { Element e = null; for (INode n : node.getChildNodes()) { e = menu.addElement("node"); initDocument(n, e); } } }
- keke82472014-06-13能说脏话么?压缩包根本就解压不开。。。。。。。还5分。
- 粉丝: 1
- 资源: 8
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助