flex tree

上次的工程使用了的是dom4j来生成xml我想大家有比我更好的方法把。在使用中,dom4j单独生成一个xml文件很容易,但是如果指定文件存放的位置,按照上个文章中的方法就不是很容易做到,总报路径无法找到的异常。我改用jdom来生成xml好像指定生成的xml的位置容易些;
package util;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.output.XMLOutputter;

import vo.JcPageTree;

public class Java2XML {
	public void BuildXMLDoc(List list) throws IOException, JDOMException {
		if(list!=null)
		{
			// 创建根节点 list;
			Element root = new Element("menus");
			// 根节点添加到文档中;
			Document Doc = new Document(root);
			// 此处 for 循环可替换成 遍历 数据库表的结果集操作;
			Iterator it = list.iterator();
			for (; it.hasNext(); ) {
				JcPageTree jc = (JcPageTree)it.next();
				// 创建节点 user;
				
				if(jc.getParentId()==0)
				{
					Element elements = new Element("node");
					elements.setAttribute("label", "" + jc.getName());
					elements.setAttribute("href", "LineList.do?parentId=" + jc.getParentId());
					elements.setAttribute("icon", "openicon" );
					root.addContent(elements);
					
				}
				
				// 给 user 节点添加子节点并赋值;
				// new Element("name")中的 "name" 替换成表中相应字段,setText("xuehui")中 "xuehui
				// 替换成表中记录值;
				//elements.addContent(new Element("node").setAttribute("label","xxx"));
				/*elements.addContent(new Element("age").setText("28"));
				elements.addContent(new Element("sex").setText("Male"));*/
				// 给父节点list添加user子节点;
				
			}
			XMLOutputter XMLOut = new XMLOutputter();
			// 输出 user.xml 文件;
			XMLOut.output(Doc, new FileOutputStream("E:\\workspace\\FlexPageMaker\\flex_src\\mycatalog.xml"));
			XMLOut.output(Doc, new FileOutputStream("E:\\workspace\\FlexPageMaker\\WebRoot\\bin\\mycatalog.xml"));
		}
		
	}

	/*public static void main(String[] args) {
		try {
			Java2XML j2x = new Java2XML();
			System.out.println("生成 mxl 文件...");
			j2x.BuildXMLDoc();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}*/
}

这个文件只要代替上篇文章中的产生xml文件的类就行了。
我实验了一下,速度很慢。我将现有的数据库数据估计有几十万条的数据,如果只查根目录还好,到那时如果一起都查出来就不行了。有人有好的方法么?这个flex生成树这么慢。。。。

你可能感兴趣的:(xml,Flex)