http://jdom.org
http://www.javaworld.com/javaworld/jw-05-2000/jw-0518-jdom.html
http://www.javaworld.com/javaworld/jw-07-2000/jw-0728-jdom2.htmlimport org.jdom.*;
import org.jdom.output.*;
import java.io.*;
public class JDomTest {
public static void main(String [] args){
Element ce = new Element(”computer”);
Document doc = new Document(ce);
ce.setAttribute(new Attribute(”id”, “089″));
ce.addContent(new Comment(”Description”));
Element hdd = new Element(”hdd”);
ce.addContent(hdd);
ce.addContent(new Element(”ram”).addContent(”삼성 128M”));
ce.addContent(new Element(”vga”).addContent(”gfmx440″));
ce.addContent(new Element(”fdd”).addContent(”1.44″));
ce.addContent(new Element(”cd-rom”).addContent(”48x”));
Element hddElement = ce.getChild(”hdd”);
boolean removed = ce.removeChild(”cd-rom”);
hdd.addContent(”20GB”);
XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat().setEncoding(”euc-kr”)) ;
try{
FileOutputStream fos = new FileOutputStream(”file.xml”);
OutputStreamWriter os = new OutputStreamWriter(fos, “euc-kr”);
outputter.output(doc, os);
os.close();
}catch(Exception e){
System.out.println(e);
}
}
} |