|
楼主 |
发表于 2005-2-23 19:43:49
|
显示全部楼层
import org.jdom.input.*;
import java.io.*;
import org.jdom.output.*;
import org.jdom.*;
import java.util.List;
public class XmlOperation {
//public static void main(String[] args) throws Exception {
// XmlOperation.PageWrite();
// XmlOperation.Read();
// XmlOperation.DirCreate();
//}
static Document doc =null;
static Element collection =null;
public static void PageWrite() throws Exception {
//boolean exists = fileExists.exists();
//if(!exists) {
if(doc==null&&collection==null){collection = new Element("Collection");
doc=new Document(collection);
}
//for(int i=0;;i++) {
String tree = IEInit.urlField.getText( );
Element page = new Element("age");
collection.addContent(page);
page.addContent(tree);
// FileWriter fw = new FileWriter(fileExists);
// out.output(doc,fw);
// fw.close();//q}
//}else {
}
public static void XMLWriter() throws Exception{
File fileExists = new File("Collection.xml");
FileWriter fw = new FileWriter(fileExists);
XMLOutputter out = new XMLOutputter();
Format format = Format.getCompactFormat();
XMLOutputter out = new XMLOutputter();
Format format = Format.getCompactFormat();
format.setEncoding("GB2312");
format.setIndent(" ");
out.setFormat(format);
out.output(doc,fw);
fw.close();
}
public static void Read() throws Exception {
SAXBuilder sax = new SAXBuilder();
Document doc = sax.build(new File("Collection.xml"));
Element collection = doc.getRootElement();
List list = collection.getChildren("age");
for(int i=0;i<list.size();i++) {
}
}
public static void DirCreate() throws Exception {
}
}
大概是 这样 |
|